我对 JQuery 有点陌生,所以如果这很明显,请原谅我。
当用户向上和向下滚动单个页面时,我正在运行此代码以向固定导航栏列表项添加/删除“活动”类。它适用于 Chrome 和 IE,但不适用于 Firefox。有人知道为什么吗?
谢谢!
// #div ids for page content
$(this).ready(function(){
var section0Height = $('#home').height();
var section1Height = $('#mission').height();
var section2Height = $('#services').height();
var section3Height = $('#team').height();
var section4Height = $('#contact').height();
// #li ids for nav items
$(window).scroll(function() {
var winTop = $(window).scrollTop();
if(winTop >= section0Height && winTop <= section1Height){
$('#section0').addClass("active").not().removeClass("active");
} else if(winTop >= section1Height && winTop <= section2Height){
$('#section1').addClass("active").not().removeClass("active");
} else if(winTop >= section2Height && winTop <= section3Height){
$('#section2').addClass("active").not().removeClass("active");
} else if(winTop >= section3Height && winTop <= section4Height){
$('#section3').addClass("active").not().removeClass("active");
} else if(winTop >= section4Height){
$('#section4').addClass("active").not().removeClass("active");
}
});
});