jQuery/[removed] scrollTop Value in all browsers?

2019-02-26 22:53发布

maybe a few others already asked that but I couldn't find any answer to the problem …

    $(window).scroll(function() {

        // Only works in Firefox and I guess in Opera
        console.log(document.documentElement.scrollTop);

        // Only works in Chrome and Safari
        console.log(document.body.scrollTop);

    });

I need this scrollTop value to be correct in every browser! What's the way to that?

Thank's in advance

1条回答
手持菜刀,她持情操
2楼-- · 2019-02-26 23:51

Use jQuery method scrolTop() it will work in all the browsers.

$(document).scrollTop()
查看更多
登录 后发表回答