jQuery的一个成功的Ajax调用后重新绑定$(窗口).scroll() [英] jQuery rebind $(window).scroll() after a successful ajax call

查看:146
本文介绍了jQuery的一个成功的Ajax调用后重新绑定$(窗口).scroll()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了这个无限滚动的剧本,但我不能重新绑定窗口滚动后,我unbinded它。这里的脚本:

  $(函数(){
    $(窗口).scroll(函数(){
        VAR mostOfTheWayDown =($(文件).height() -  $(窗口).height())* 2/3;
        如果($(窗口).scrollTop()> = mostOfTheWayDown){
            $(窗口).unbind(滚动);
            $阿贾克斯({
                网址:loadmore,
                数据:{lastrank:lastrank},
                数据类型:JSON,
                键入:POST,
                成功:函数(JSON){
                    //一些工作在这里
                    $(窗口).bind(滚动);
                }
            });
        }
    });
});
 

我怎样才能重新绑定窗口滚动一个成功的Ajax调用后?

解决方案

  $(函数(){
    VAR scrollFunction =功能(){
        VAR mostOfTheWayDown =($(文件).height() -  $(窗口).height())* 2/3;
        如果($(窗口).scrollTop()> = mostOfTheWayDown){
            $(窗口).unbind(滚动);
            $阿贾克斯({
                网址:loadmore
                数据:{lastrank:lastrank},
                数据类型:JSON,
                键入:POST,
                成功:函数(JSON){
                    //一些工作在这里

                    $(窗口).scroll(scrollFunction);
                }
            });
        }
    };
    $(窗口).scroll(scrollFunction);
});
 

I have made this infinitely scrolling script, but I can't rebind the window scroll after I unbinded it. Here's the script:

$(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');
                }
            });
        }
    });
});​

How can I rebind the window scroll after a successful ajax call?

解决方案

$(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);
});​

这篇关于jQuery的一个成功的Ajax调用后重新绑定$(窗口).scroll()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆