开发者

jQuery: Show "back-to-top" link on scroll? not working on windows?

开发者 https://www.devze.com 2023-03-15 22:52 出处:网络
i have the following situation. I\'m having a really long webpage where I want to have a little \"back to top link\" at the side of the page (absolute positioned). I want to show the link only if the

i have the following situation. I'm having a really long webpage where I want to have a little "back to top link" at the side of the page (absolute positioned). I want to show the link only if the user is scrolling and the scroll position is larger than 100px from the top. Moreover I'm constrain the behaviour only to screens larger than 300px and Non-iOS devices.

This is my code:

//Back to top
$(window).scroll(function () {

    if ( $(window).width() > 300 || !isiOS ) {

        if ($('body').scrollTop() > 100) {
            $('#back-to-top').fadeIn('fast');
        } else {
            $('#back-to-top').fadeOut('fast');
        }

    }

});

$(window).scroll();

The problem is it works fine on my mac. However it does not work on Windows machines. It works in Chrome on windows, but doesn't in any IE 开发者_运维问答version, nor Firefox, nor anything else. It works in every major browser on my mac.

Any idea what could cause that or why it's buggy?

Thank you for your help!


Try $(window).scrollTop() instead of $('body').scrollTop()

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号