jQuery / Javascript:所有浏览器中的scrollTop值? [英] jQuery/Javascript: scrollTop Value in all browsers?

查看:101
本文介绍了jQuery / Javascript:所有浏览器中的scrollTop值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

也许其他几个人已经问过但我找不到问题的答案...

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);

    });

我需要这个scrollTop值在每个浏览器中都是正确的!
这是怎么回事?

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

提前谢谢

推荐答案

使用jQuery方法 scrolTop()它可以在所有浏览器中使用。

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

$(document).scrollTop()

这篇关于jQuery / Javascript:所有浏览器中的scrollTop值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆