Iβm working on a page with a fixed menu that is selected after the user scrolls a certain distance from the top, and when they scroll down the page, a different class is assigned to the various links from the menu that changes color. All this works well in Chrome and Safari, but in Firefox page freezes at the top. I am wondering if any code is overflowing ... essentially freezes the window.
Here is my code.
$.localScroll({
onBefore: function() {
$('body').data('scroll-executing', true);
},
onAfter: function() {
$('body').data('scroll-executing', false);
$(window).trigger("scroll");
}
});
$(window).scroll(function () {
if ($(this).scrollTop() > 259) {
$('.nav').addClass("f-nav");
} else {
$('.nav').removeClass("f-nav");
}
});
$(window).scroll(function() {
if ($('body').data('scroll-executing')) {
return;
}
$("a").removeClass('active');
var scroll = $(window).scrollTop();
if (scroll > 2150) {
$("#nav_3").removeClass('active');
$("#nav_5").attr('class', 'active');
setHash("contact");
} else if (scroll > 1300) {
$("#nav_2").removeClass('active');
$("#nav_3").attr('class', 'active');
setHash("portfolio");
} else if (scroll > 400) {
$("#nav_2").attr('class', 'active');
setHash("about");
} else if (scroll <= 380) {
$("#nav_1").attr('class', 'active');
setHash("home");
}
});
I forgot to add a definition to setHash. Here it is.
setHash = function(hash) {
var scrollmem = $('body').scrollTop();
window.location.hash = hash;
$('html,body').scrollTop(scrollmem);
}
I also noticed that the processor reaches 100%, and I canβt understand why.
, else if (scroll <= 380). - . - , -, ... , firefox ?
... jquery , , .
.