Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
410 views
in Technique[技术] by (71.8m points)

javascript - 如何使用jQuery检测页面的滚动位置(How to detect scroll position of page using jQuery)

I am having trouble with jQuery functionality on my website.(我在我的网站上无法使用jQuery功能。)

What it does, is that it uses the window.scroll() function to recognize when the windows changes its scroll position and at the change calls a few functions to load data from the server.(它的作用是使用window.scroll()函数来识别窗口何时更改其滚动位置,并在更改时调用一些函数来从服务器加载数据。) The problem is the .scroll() function is called as soon as there is even a little change in the scroll position and loads data at the bottom;(问题在于, .scroll()滚动位置有一点变化并在底部加载数据,就会立即调用.scroll()函数。) however, what I wish to achieve is to load new data when the scroll/page position reaches at the bottom, like it happens for Facebook feed.(但是,我希望实现的是在滚动/页面位置到达底部时加载新数据,就像Facebook feed那样。) But I am not sure how to detect scroll position using jQuery?(但是我不确定如何使用jQuery检测滚动位置吗?) function getData() { $.getJSON('Get/GetData?no=1', function (responseText) { //Load some data from the server }) }; $(window).scroll(function () { getData(); });   ask by Maven translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can extract the scroll position using jQuery's .scrollTop() method(您可以使用jQuery的.scrollTop()方法提取滚动位置)

$(window).scroll(function (event) { var scroll = $(window).scrollTop(); // Do something });

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...