jQuery在回调结束页面滚动 [英] jQuery Callback on end of page scroll
问题描述
我有一个div标签设置为overflow:在css中滚动。
我有一个回调,应该在使用这个元素的滚动结束时调用。
i have a div tag which is set to overflow:scroll in css.
i have a callback which is supposed to be called on the end of scroll of the element which is found using this.
$('#details').scroll( function () {
if ($(this).height() == ($(this).get(0).scrollHeight - $(this).scrollTop())) {
getDetails($("span:last").attr("id"), 3);
}
});
其中getDetails是回调im使用。它需要一个div内的span的最后一个元素,并将其作为一个值发送。它所有的ajax调用。问题是getDetails被称为三次每次我悬停到div的结尾。关于我如何调用一次的任何建议?
where getDetails is the callback im using. it takes the last element of the span inside a div and sends it as a value. its all ajax calls. problem is getDetails gets called thrice everytime i hover to the end of the div. any suggestions on how i make it to be called once?
重复的回调发生只有当我使用滚轮或按滚动条按钮下来。
推荐答案
我没有测试这个问题,工作。它的相当黑客虽然...
I didn't test this, but something along these lines might work. Its quite hacky though...
$('#details').data("didfire", false).scroll( function () {
if ($(this).height() == ($(this).get(0).scrollHeight - $(this).scrollTop())) {
if(!$(this).data("didfire")) {
getDetails($("span:last").attr("id"), 3);
$(this).data("didfire", true)
var ref = $(this);
setTimeout(function(){
ref.data("didfire", false);
}, 500);
}
}
});
这篇关于jQuery在回调结束页面滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!