jQuery/Javascript: scrollTop Value in all browsers?

孤街浪徒 提交于 2019-12-02 05:18:52

问题


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:


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

$(document).scrollTop()


来源:https://stackoverflow.com/questions/9231601/jquery-javascript-scrolltop-value-in-all-browsers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!