jQuery 如何检查网页页面是否滚动?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3074802/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 14:49:22  来源:igfitidea点击:

How to check if webpage page is scrolled?

jqueryinternet-explorerscrollmouse-position

提问by Muzzammil Hussain

Is there any way in javascript to check if web page has been vertically scrolled? specially for Internet Explorer? I need to get the mouse position in IE but using jQuery event e.pageY it gives correct value when page is not scrolled but when page is scrolled down then it gives wrong position.

javascript中有什么方法可以检查网页是否已垂直滚动?专门用于 Internet Explorer?我需要在 IE 中获取鼠标位置,但是使用 jQuery 事件 e.pageY 它在页面未滚动时给出正确的值,但是当页面向下滚动时,它给出了错误的位置。

采纳答案by Peter Jaric

Check out this question if you are comfortable with using jQuery:

如果您对使用 jQuery 感到满意,请查看这个问题:

How do I determine height and scrolling position of window in jQuery?

如何确定 jQuery 中窗口的高度和滚动位置?

回答by Nick Craver

In case any future googlers find this, the quick example is:

万一未来的谷歌员工发现这一点,简单的例子是:

if(!$(window).scrollTop()) { //abuse 0 == false :)
  alert("You are at the top of this window");
}