我是JavaScript的新手,仍然可以解决问题。
我设法使导航仅出现在顶部和向上滚动。问题是,一旦它位于顶部,我就需要返回透明背景,但是在更改启动后它仍保持灰色。
/* 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("navbar").style.top = "0";
document.getElementById("navbar").style.background = "#2b2b2b";
document.getElementById("totop").style.bottom = "-120px";
} else {
document.getElementById("navbar").style.top = "-50px";
document.getElementById("navbar").style.background = "transparent";
document.getElementById("totop").style.bottom = "0px";
}
prevScrollpos = currentScrollPos;
}