我工作在页面上有一个固定的菜单,用户之后拿起滚动了从顶部一定距离,当他们向下滚动页面,从菜单中选择不同的链接中给出一个改变颜色的类。所有这些在Chrome和Safari中似乎都能很好地工作,但在Firefox中,页面在顶部冻结。我想知道它是否不断循环一些代码......实质上是冻结了窗口。window.scroll功能冻结火狐
这是我的代码。
$.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;
}
// find the a with class 'active' and remove it
$("a").removeClass('active');
// get the amount the window has scrolled
var scroll = $(window).scrollTop();
// add the 'active' class to the correct #nav based on the scroll amount
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) { //when I remove this section, the problem goes away.
$("#nav_1").attr('class', 'active');
setHash("home");
}
});
我忘了添加setHash定义。这里是。
setHash = function(hash) {
var scrollmem = $('body').scrollTop();
window.location.hash = hash;
$('html,body').scrollTop(scrollmem);
}
我也注意到CPU上升到100%,我似乎无法弄清楚为什么。
的问题是在代码与其他开始第三部分,如果(滚动< = 380)。我想通过消除的过程。任何人都可以看到它循环或做一些永远不会结束的事情......或者可以解释为什么firefox会在页面顶部冻结?
我是新来的这一切......我刚拿起的jQuery在过去的几天里,我已经基本google搜索了很多,适应代码,以便它适合我的需要。
任何帮助将不胜感激。
你能给出一个链接到一个示例页面,显示问题,也许在jsfiddle.net或类似的东西? –