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

前端 未结 4 503
天涯浪人
天涯浪人 2020-12-15 16:17

Not sure if there\'s another question regarding this, if so I apologize and please don\'t release the hounds.

Using the html5 doctype and doing a quick console.log o

相关标签:
4条回答
  • 2020-12-15 16:27

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

    0 讨论(0)
  • 2020-12-15 16:30

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

    0 讨论(0)
  • 2020-12-15 16:40

    $(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/

    0 讨论(0)
  • 2020-12-15 16:40

    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?

    0 讨论(0)
提交回复
热议问题