我正在尝试更改滚动菜单bg,我被卡在了这里。“ addClass”只是不适用。我有这样的短信:
<nav>
<ul>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</nav>
的CSS
nav {
position: fixed;
right: 0;
left: 0;
margin: 0;
min-height: 50px;
padding: 10px;
z-index: 3;
transition: all .3s ease-in-out;
}
nav.scrolling {
background-color: #424242;
}
JS
$(window).scroll(function() {
var scroll = $(window).scrollTop();
if (scroll >= 500) {
$("nav").addClass("scrolling");
} else {
$("nav").removeClass("scrolling");
}
});
麻烦出在
html {
height: 100%;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句