jQuery 功能在 Firefox 中不起作用

jQuery function not working in Firefox

我有一个基本的 "scroll to top" jQuery 功能可以在我的网站上使用。此功能在 Chrome、Opera 和 IE 中如我所愿,但在我的 Firefox (37.0.2) 中却没有。

函数如下:

function scrollUp(){
    $("#to-top").hide();

    $(window).bind('mousewheel', function(){
        var num = $(window).scrollTop();

        if (num > 100){
            $("#to-top").show(500);
        };
        if (num < 100){
            $("#to-top").hide();
        };

        $("#to-top").click(function(){
            $("#to-top").hide();
            $('body,html').stop().animate({scrollTop:0},1200);
        });
    });
}

scrollUp();

我已经检查了 Firefox 中的检查元素框,但没有出现任何错误。

要实现这一点,HTML 是:

<a id="to-top">
    <center><p>^ ^ ^</p><p>Scroll To Top</p></center>
</a>
<script src="../scripts/toTop.js">scrollUp()</script>

位于页面底部结束正文标记之前。

HTML 在 firefox 中没有显示任何内容,这意味着 jQ 函数的第一行一定在工作,但之后由于某种原因它没有工作。

我最初使用的是 .on() 而不是 .bind() 它们在其他浏览器中的功能相同购买不是 firefox....

感谢任何帮助,谢谢大家!

使用 scroll 事件并使用 .on

绑定
$(document).on('scroll', function () { /* your mousewheel code here */ });

如果没记错的话,Firefox 不喜欢 mousewheel 事件。不过,我很确定 scroll 事件应该有效。

此外,您不需要每次 scrollUp() 运行 $(window).bind。这只需要在 $(document).ready

上完成