Я новичок в HTML, CSS и JQuery.В настоящее время я пытаюсь написать свой собственный сайт.В моем коде я использовал две разные функции jquery, но может работать только одна из них.Как я могу редактировать свой код, чтобы обе функции работали?Возможно, ответ прост, но я пока не знаю, как туда добраться ..
Мой текущий скрипт jquery:
<script>
// When the user scrolls down 20px from the top of the document, show the button
window.onscroll = function() {scrollFunction()};
function scrollFunction() {
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
document.getElementById("myBtn").style.display = "block";
} else {
document.getElementById("myBtn").style.display = "none";
}
}
// When the user clicks on the button, scroll to the top of the document
function topFunction() {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
}
// When the user scrolls down, hide the navbar. When the user scrolls up, show the navbar */
var prevScrollpos = window.pageYOffset;
window.onscroll = function() {
var currentScrollPos = window.pageYOffset;
if (prevScrollpos > currentScrollPos) {
document.getElementById("nav").style.top = "0";
} else {
document.getElementById("nav").style.top = "-100px";
}
prevScrollpos = currentScrollPos;
}
</script>
Большое спасибо.