JQuery滚动无法在Internet Explorer或Firefox中运行

时间:2015-02-17 17:11:12

标签: javascript jquery internet-explorer firefox

我正在使用一些JQuery来显示/隐藏我正在构建的新视差滚动网页上的一些操作按钮。滚动PAST 100px后,它会显示操作按钮。如果向上滚动,操作按钮将消失。

它在Chrome中运行良好,但在Firefox或Internet Explorer中无效。我在页面上使用其他JQuery,它在Firefox和Internet Explorer中正确启动。

Live demo of the parallax scrolling site

JSFiddle of the code in question

以下是相关代码:

$(document).ready(function () {
slider();

});

$(window).scroll(function () {
    slider();
});

function slider() {
    if (document.body.scrollTop > 100)
        $('#request').stop().animate({"bottom": '10'});
    else
        $('#request').stop().animate({"bottom": '-75'});
}

1 个答案:

答案 0 :(得分:1)

经过一番深入研究后,我发现Firefox和IE识别了#34; top"不同以后我改变了代码:

if (document.body.scrollTop > 100)

为:

if  ($(window).scrollTop() + 1 > 100)

并且代码完美无缺!