[英]My sticky navbar js script doesn't work
I can't get the sticky navbar to work. 我无法让粘性导航栏工作。 It is supposed to stick to the top once you scroll over the header.
一旦滚动标题,它应该贴在顶部。 Am I not triggering the right classes?
我没有触发正确的课程吗?
var n=$(".navbar");
ns=".navbar-scrolled";
head=$('header').height();
$(window).scroll(function() {
if( $(this).scrollTop() > head) {
n.addClass(ns);
}
else {
n.removeClass(ns);
}
You don't need .
你不需要
.
to add new class attribute. 添加新的类属性。
ns
and head
is a variable, so you should add var
before the statement or you can separate it by comma. ns
和head
是一个变量,所以你应该在语句之前添加var
,或者你可以用逗号分隔它。
Here's working demo https://jsfiddle.net/alfrcr/jsuc4kL5/2/ 这是工作演示https://jsfiddle.net/alfrcr/jsuc4kL5/2/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.