我在网站上遇到jQuery功能问题。它的作用是,它使用 window.scroll()函数来识别窗口何时改变其滚动位置,并且在更改时调用一些函数来加载来自服务器。
I am having trouble with jQuery functionality on my website. 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.
问题是只要有一点变化就会调用 .scroll()函数在滚动位置并在底部加载数据;但是,我希望实现的是当滚动/页面位置到达底部时加载新数据,就像Facebook Feed一样。
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; 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.
但我不确定如何使用jQuery检测滚动位置?
But I am not sure how to detect scroll position using jQuery?
function getData() { $.getJSON('Get/GetData?no=1', function (responseText) { //Load some data from the server }) }; $(window).scroll(function () { getData(); });推荐答案
您可以使用jQuery的 .scrollTop() method
You can extract the scroll position using jQuery's .scrollTop() method
$(window).scroll(function (event) { var scroll = $(window).scrollTop(); // Do something });更多推荐
如何使用jQuery检测页面的滚动位置
发布评论