JavaScript无法在Firefox中运行

时间:2012-04-08 16:03:34

标签: javascript jquery

JavaScript的:

$(window).scroll(function(){
    if  ($(window).scrollTop() == $(document).height() - $(window).height()){
        $('#footer').show();
    }
});

CSS:

#footer {
    display: none;
}

这应该在页面底部向下滚动到底部时显示隐藏的div。出于某种原因,隐藏的div永远不会在Firefox中显示。是否有另一种使用jQuery创建相同效果的方法?

编辑:这是在Firefox中无法正常工作的页面

http://safe.tumblr.com/theme/preview/34069

2 个答案:

答案 0 :(得分:2)

你需要使用它:

$(window).scroll(function() {
   if($(window).scrollTop() + $(window).height() == $(document).height()) {
       $('#footer').show();
   }
});

答案 1 :(得分:0)

scrollTop的最大值与documentHeight - windowHeight给你的最大值之间可能存在细微差别,因此我建议减去一个小的安全系数:

$(window).scroll(function(){
    if ($(window).scrollTop() >= $(document).height() - $(window).height() - 3) {
        $('#footer').show();
    }
});