addClass 在项目中不起作用
addClass not working in the project
我正在尝试更改滚动菜单背景,但我被困在这里。 "addClass" 只是不适用。我有这样的 smt:
<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");
}
});
它正在 JSfiddle 上工作,但不在我的项目中。
问题出在
html {
height: 100%;
}
我正在尝试更改滚动菜单背景,但我被困在这里。 "addClass" 只是不适用。我有这样的 smt:
<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");
}
});
它正在 JSfiddle 上工作,但不在我的项目中。
问题出在
html {
height: 100%;
}