[英]When scrolled to top of window, load results jQuery
I have a function that when i click a button I call more results from my table, Im trying to get this to work when the button is 100px top of the window, however I cant seem to get it to work... 我有一个功能,当我点击一个按钮,我从我的表调用更多的结果,我试图让这个工作当按钮是100px的窗口顶部,但我似乎无法让它工作...
$(function(){
$('#showMore').click(function(event) {
event.preventDefault();
var number = $(".directory").children().length;
$.ajax({
type: "POST",
url: "getentries.php",
data: "count="+number,
success: function(results){
$('.directory').append(results);
}
});
});
}); });
So far ive tried 到目前为止,我试过了
$(function(){
$('#showMore').offset(function(event) {
....
The jQuery .offset()
function is not for establishing an event handler. jQuery
.offset()
函数不用于建立事件处理程序。 You're looking for .scroll()
. 您正在寻找
.scroll()
。 In the event handler for "scroll" events, you can use .offset()
to find out the current position. 在“滚动”事件的事件处理程序中,您可以使用
.offset()
来查找当前位置。
I'll offer the caveat that browsers fire a lot of scroll events, so you may want to introduce a delay before doing any serious work in response to the user scrolling the window. 我将提供一些警告,即浏览器会触发大量滚动事件,因此您可能需要在执行任何认真工作之前引入延迟以响应用户滚动窗口。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.