jQuery重新绑定事件函数 $(文档).ready(函数(e){ sample();//初始化函数 } 函数示例(){ $(文档)。滚动(功能(e){ var scroll_top=$(窗口).scrollTop(); var document_bottom=滚动_top+$(窗口).height(); var elementTop=$('.load more').offset().top; var elementBottom=(elementTop+$('.load more').height()-50)//50 px偏移量; if((elementBottom=scroll\u top))//用户几乎到达可见项的末尾,因此加载更多数据。类似于无限滚动 { $(document).unbind(“scroll”);//在加载完成之前阻止进一步的请求 $.ajax({ url:“sample”//AJAX加载的Sampel url 键入:“获取”, 数据:{ 起点:1 },//样本数据 数据类型:“html”, 成功:功能(数据){ 数据=$(数据); $(“#呈现的类别”).append(数据).mashise('append',数据);//mashise append项 $(document).bind(“scroll”);//重新绑定滚动事件 } }); } }); }//示例函数到此结束

jQuery重新绑定事件函数 $(文档).ready(函数(e){ sample();//初始化函数 } 函数示例(){ $(文档)。滚动(功能(e){ var scroll_top=$(窗口).scrollTop(); var document_bottom=滚动_top+$(窗口).height(); var elementTop=$('.load more').offset().top; var elementBottom=(elementTop+$('.load more').height()-50)//50 px偏移量; if((elementBottom=scroll\u top))//用户几乎到达可见项的末尾,因此加载更多数据。类似于无限滚动 { $(document).unbind(“scroll”);//在加载完成之前阻止进一步的请求 $.ajax({ url:“sample”//AJAX加载的Sampel url 键入:“获取”, 数据:{ 起点:1 },//样本数据 数据类型:“html”, 成功:功能(数据){ 数据=$(数据); $(“#呈现的类别”).append(数据).mashise('append',数据);//mashise append项 $(document).bind(“scroll”);//重新绑定滚动事件 } }); } }); }//示例函数到此结束,jquery,bind,unbind,Jquery,Bind,Unbind,重新绑定滚动不起作用。此过程错误吗?当前您将滚动事件绑定为空。 在这里,我提取了该函数并创建了名为myfunction的新函数,并用该函数绑定了滚动事件 简明的 $(document).ready(function (e) { sample(); // Initialize the function } function sample() { $(document).scroll(function (e) { var scroll_top = $(window)

重新绑定滚动不起作用。此过程错误吗?

当前您将滚动事件绑定为空。

在这里,我提取了该函数并创建了名为
myfunction
的新函数,并用该函数绑定了滚动事件

简明的

$(document).ready(function (e) {
    sample(); // Initialize the function
}

function sample() {
    $(document).scroll(function (e) {
        var scroll_top = $(window).scrollTop();
        var document_bottom = scroll_top + $(window).height();
        var elementTop = $('.load-more').offset().top;
        var elementBottom = (elementTop + $('.load-more').height() - 50) // 50 px offset;
        if ((elementBottom <= document_bottom) && (elementTop >= scroll_top)) // User almost reach the end of visible items so load more data. Similar to infinite scroll
        {
            $(document).unbind("scroll"); // To prevent further requests until the load is complete
            $.ajax({
                url: "sample", // Sampel URl for AJAX load
                type: "GET",
                data: {
                    start: 1
                }, // Sample data
                dataType: "html",
                success: function (data) {
                    data = $(data);
                    $('#categories-rendered').append(data).masonry('appended', data); // Masonry append items
                    $(document).bind("scroll"); // To rebind the scroll event
                }
            });
        }
    });
} // Sample function ends here
完整代码

var myfunction = function (e) {//Your logic};
$(document).bind("scroll", myfunction );
$(document).unbind("scroll");
$(文档).ready(函数(e){
sample();//初始化函数
});
函数示例(){
$(文档)。滚动(myfunction);
//创建一个单独的函数
函数myfunction(e){
var scroll_top=$(窗口).scrollTop();
var document_bottom=滚动_top+$(窗口).height();
var elementTop=$('.load more').offset().top;
var elementBottom=(elementTop+$('.load more').height()-50)//50 px偏移量;
if((elementBottom=scroll\u top))//用户几乎到达可见项的末尾,因此加载更多数据。类似于无限滚动
{
$(document).unbind(“scroll”);//在加载完成之前阻止进一步的请求
$.ajax({
url:“sample”//AJAX加载的Sampel url
键入:“获取”,
数据:{
起点:1
},//样本数据
数据类型:“html”,
成功:功能(数据){
数据=$(数据);
$(“#呈现的类别”).append(数据).mashise('append',数据);//mashise append项
//重新绑定你的函数
$(document).bind(“scroll”,myfunction);//重新绑定滚动事件
}
});
}
}
}//示例函数到此结束

尝试将事件放入函数中:

$(document).ready(function (e) {
    sample(); // Initialize the function
});

function sample() {
    $(document).scroll(myfunction);

    //Create a seperate function 
    function myfunction(e) {
        var scroll_top = $(window).scrollTop();
        var document_bottom = scroll_top + $(window).height();
        var elementTop = $('.load-more').offset().top;
        var elementBottom = (elementTop + $('.load-more').height() - 50) // 50 px offset;
        if ((elementBottom <= document_bottom) && (elementTop >= scroll_top)) // User almost reach the end of visible items so load more data. Similar to infinite scroll
        {
            $(document).unbind("scroll"); // To prevent further requests until the load is complete
            $.ajax({
                url: "sample", // Sampel URl for AJAX load
                type: "GET",
                data: {
                    start: 1
                }, // Sample data
                dataType: "html",
                success: function (data) {
                    data = $(data);
                    $('#categories-rendered').append(data).masonry('appended', data); // Masonry append items

                    //rebind with your function
                    $(document).bind("scroll", myfunction); // To rebind the scroll event
                }
            });
        }
    }
} // Sample function ends here
您遇到的问题是使用匿名函数

var e = function (e) { ... };
$(document).bind("scroll", e);
$(document).unbind("scroll", e);