jQuery无限滚动插件-加载和内存问题 [英] jquery infinite scroll plugin - loading and memory issues

查看:165
本文介绍了jQuery无限滚动插件-加载和内存问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用无限滚动插件(Paul Irish).我要在下一页加载时和到达maxPage时使用自定义函数.

I am using infinate scroll plugin (by Paul Irish). I want to use custom functions when the next page is loading and when the maxPage is reached.

我已经根据文档尝试了以下方法,但是这将启动加载功能,但从未调用完成功能.当我在控制台中查看时,它也不调用下一页.我想念什么?

I have tried the below based on the documentation, however this starts the loading function but doesn't ever call the finished function. Its not calling the next page either when I look in the console. What am I missing?

    // Infinite Ajax Scroll configuration
    $container.infinitescroll({
        navSelector: "div.paginate",
        nextSelector: "div.paginate a",
        itemSelector: "div.element",
        maxPage: 5,
        loading: {
            start: function(){
                  alert('started');
            },
            finished: function(){
                  alert('finsihed loading');
            }
        }
    },
    function(newElements) {

        var $newElements = $(newElements).css({opacity: 0});
        //remove the first item
        $newElements.splice(0, 1);

            $container.isotope('appended', $newElements);

        }

    });
});

页面和页面的滚动可能会继续进行,直到浏览器由于内存问题而崩溃为止,因此,当当前页面到达maxPage时,我需要停止无限滚动,并允许用户选择加载更多"按钮.希望能解决内存问题.

The scrolling could go on for pages and pages until the browser crashes due to memory issues, I therefore need to stop infinite scrolling when the current page gets to maxPage and allow the user to select a "Load More" button. Hopefully solving memory issues.

下面的链接中对此进行了讨论,但是我找不到任何有关如何准确执行此操作的文档,甚至无法使上述示例正常工作.

This is discussed in the link below but I cannot find any further documentation on how to do this exactly and cann't even get the above sample to work.

https://github.com/paulirish/infinite-scroll/issues/300

推荐答案

首先,确保它可以使用最少的选项(加上控制台调试消息):

First, ensure it works will the minimum options (plus console debug messages):

$container.infinitescroll({
    navSelector: "div.paginate",
    nextSelector: "div.paginate a",
    itemSelector: "div.element",
    debug: true
});

如果有,请添加选项,直到其中断.

If it does, add in options until it breaks.

我建议在控制台中调试启动/完成功能,如下所示:

I recommend debugging the start/finished functions in the console, like this:

    loading: {
        start: function(){
              console.log('started');
        },
        finished: function(){
              console.log('finsihed loading');
        }
    }

考虑添加errorCallback选项来调试ajax问题.

Consider adding the errorCallback option to debug ajax issues.

这篇关于jQuery无限滚动插件-加载和内存问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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