gpt4 book ai didi

javascript - ajax 调用成功后,jQuery 重新绑定(bind) $(window).scroll()

转载 作者:行者123 更新时间:2023-11-30 08:11:49 25 4
gpt4 key购买 nike

我已经制作了这个无限滚动的脚本,但是我在解除绑定(bind)后无法重新绑定(bind)窗口滚动。这是脚本:

$(function(){
$(window).scroll(function(){
var mostOfTheWayDown = ($(document).height() - $(window).height()) * 2 / 3;
if ($(window).scrollTop() >= mostOfTheWayDown) {
$(window).unbind('scroll');
$.ajax({
url: 'loadmore',
data: {lastrank: lastrank},
dataType: 'json',
type: 'POST',
success: function(json){
//some work here
$(window).bind('scroll');
}
});
}
});
});​

如何在成功调用 ajax 后重新绑定(bind)窗口滚动条?

最佳答案

$(function(){
var scrollFunction = function(){
var mostOfTheWayDown = ($(document).height() - $(window).height()) * 2 / 3;
if ($(window).scrollTop() >= mostOfTheWayDown) {
$(window).unbind("scroll");
$.ajax({
url: "loadmore",
data: {lastrank: lastrank},
dataType: "json",
type: "POST",
success: function(json){
//some work here

$(window).scroll(scrollFunction);
}
});
}
};
$(window).scroll(scrollFunction);
});​

关于javascript - ajax 调用成功后,jQuery 重新绑定(bind) $(window).scroll(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9249047/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com