所以我有这样的情况,我想在单击的链接上重新绑定无限滚动插件,并传递新的URL,以改变稍后将由其生成的内容部分。

到目前为止,我所能做的是触发无限滚动并在第一个单击的链接处传递该部分。.此后,当我单击另一个链接时,URL链接或该部分将不会重新绑定,我希望将其重新绑定以便可以改变生成的内容。

更何况这是我的代码。

的HTML

<li class="active"><a href="#" title="" data-filter=".w-all" class="w-filter">View All</a></li>
        <li><a href="#" title="" data-filter=".w-branding" class="w-filter">Branding</a></li>
        <li><a href="#" title="" data-filter=".w-graphic" class="w-filter">Graphic</a></li>
        <li><a href="#" title="" data-filter=".w-website" class="w-filter">Website</a></li>
        <li><a href="#" title="" data-filter=".w-photography" class="w-filter">Photography</a></li>


jQuery的

$('a.w-filter').click(function(e){
    var selector = $(this).attr('data-filter');
    var section = selector.split('-');
    $('#page_nav a').attr('href', 'pager/1/'+section[1]);


    $(window).unbind('.infscr');

    $container.infinitescroll({
        navSelector : '#page_nav',
        nextSelector : '#page_nav a',
        itemSelector : '.item',
        loading: {
            finishedMsg: 'Hmm, I guess that\'s all we got.',
            img: 'loading.gif',
            msgText: '<em>Loading more projects.</em>'
        },
        pathParse: function (path, currentPage) {
          var chunkedUrl = ['/pager/', '/'+section[1]];
          return chunkedUrl;
        }


    });

    $container.infinitescroll('retrieve');


    e.preventDefault();
});


能做到吗

最佳答案

终于,我找到了这个Infinite scroll plugin modify the path with custom query的答案

它必须稍微修改插件源代码,然后才能像魅力一样工作!

//line 67
$.infinitescroll.prototype = {
   //My custom parameters
    pageType: "&type=items",
    categoryParam: "&category=shoes",
    /*
        ----------------------------
        Private methods
        ----------------------------
        */


感谢花花公子..

我又发现了一些与此有关的问题..因此,当任何部分返回0结果时,插件将调用“ end”函数,该实例将销毁实例,然后,当我单击任何链接时,插件将不再触发该事件。我试图使用其“绑定”功能重新绑定该实例,但是没有运气,它的“获取”功能仅在完成销毁的消息文本被销毁之前将其称为上一个实例的最后状态。我仍然无法重新绑定新实例。

这是我所做的唯一选择,n还需要修改插件源。
当某节返回0结果时,它不会调用'end'函数,但是该插件将不再显示完成的文本消息。

// near line 356, put comments tag before if(children.length === 0) to its closing brackets

// if it didn't return anything
/*if (children.length === 0) {
    return this._error('end');
}*/

// use a documentFragment because it works when content is going into a table or UL
frag = document.createDocumentFragment();


仍然希望有人能以正确的方式解决此问题。

关于jquery - 单击时使用新的URL链接重新绑定(bind)infinitescroll插件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18420722/

10-12 00:16
查看更多