我正在使用这段jquery代码在页面滚动浏览某些部分时切换标题类,但它似乎在Firefox中不起作用。怎么了?
//toggle header class
var whiteSections = $(".our-products, .our-clients, .team, .about-us");
var header = $("header");
$(window).on("scroll", function(e) {
var scrollTop = document.body.scrollTop + 90;
var scrollBottom = document.body.scrollTop - 90;
var dark = false;
whiteSections.each(function() {
var $this = $(this);
var top = $this.offset().top;
if (top <= scrollTop && top + $this.height() >= scrollBottom) {
dark = true;
return false;
}
});
header.toggleClass("dark", dark);
});