我的网站上的jQuery功能有问题。它所做的是,它使用window.scroll()
函数来识别窗口何时更改其滚动位置,并在更改时调用几个函数从服务器加载数据。
问题是,只要滚动位置有一点变化,.scroll()
函数就会被调用,并在底部加载数据;然而,我希望实现的是在滚动/页面位置到达底部时加载新数据,就像Facebook feed一样。
但是我不确定如何使用jQuery来检测滚动位置?
function getData() {
$.getJSON('Get/GetData?no=1', function (responseText) {
//Load some data from the server
})
};
$(window).scroll(function () {
getData();
});
发布于 2013-07-03 14:28:47
可以使用jQuery的.scrollTop()
方法提取滚动位置
$(window).scroll(function (event) {
var scroll = $(window).scrollTop();
// Do something
});
发布于 2013-07-03 14:39:18
您正在寻找window.scrollTop()
函数。
$(window).scroll(function() {
var height = $(window).scrollTop();
if(height > some_number) {
// do something
}
});
发布于 2013-07-03 15:03:35
查看此处演示http://jsfiddle.net/yeyene/Uhm2J/
function getData() {
$.getJSON('Get/GetData?no=1', function (responseText) {
//Load some data from the server
})
};
$(window).scroll(function() {
if($(window).scrollTop() + $(window).height() == $(document).height()) {
alert("bottom!");
// getData();
}
});
https://stackoverflow.com/questions/17441065
复制相似问题