scrollTop() returns 0 in Firefox, but not in Chrome

风格不统一 提交于 2019-11-29 01:00:55

Try to use var scrollTop = $(document).scrollTop();

Andrejs Kuzmins

$(window).scrollTop() works as expected in both Firefox and Chrome.

For verification run the following jsfiddle in both chrome and firefox: http://jsfiddle.net/RBBw5/6/

After some frustration with IE9 in quirks mode, I've found the that $('body').scrollTop() works reliably in IE9, Chrome 32 and Firefox 26.

Matt Robinson

Use var scrollTop = $('html').scrollTop(); works for FireFox

You'll need to sniff the browser out though (I know, feature detect, not sniff, but you can't detect this), because it won't work in Chrome, try here :

Easiest/Lightest Replacement For Browser Detection jQuery 1.9?

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