无限滚动不适用于 Will Paginate 和 Masonry

发布于 2025-01-07 22:51:16 字数 2010 浏览 0 评论 0原文

我使用了 Masonry、Will Paginate 和 Infinite Scroll 的组合。 Masonry 和 Will Paginate 工作正常,但我似乎无法让无限滚动工作。

我有一种感觉,我的选择器可能是错误的,但在尝试了不同的变化后我仍然一无所知。

脚本

<script type="text/javascript">
 $(function(){

    var $container = $('#container');
    $container.imagesLoaded( function(){
      $container.masonry({
        itemSelector : 'item'
      });

    });

  });

// infinitescroll() is called on the element that surrounds 
// the items you will be loading more of
  $('#container').infinitescroll({

    navSelector  : '.pagination',            
                   // selector for the paged navigation (it will be hidden)
    nextSelector : '.pagination .next_page a',    
                   // selector for the NEXT link (to page 2)
    itemSelector : '#container .item'         
                   // selector for all items you'll retrieve
    },
    // trigger Masonry as a callback
    function ( newElements ) {
        var $newElems = $( newElements );
        $container.masonry( 'appended', $newElems );
    }
  );

</script> 

导航

<div class="pagination">
<span class="previous_page disabled">← Previous</span>
     <em>1</em>
     <a href="/?page=2" rel="next">2</a>
     <a href="/?page=3">3</a>
     <a href="/?page=4">4</a>
     <a href="/?page=5">5</a>
     <a href="/?page=6">6</a>
     <a href="/?page=7">7</a>
     <a class="next_page" href="/?page=2" rel="next">Next →</a>
</div>

内容

<div id="container" class="masonry" style="position: relative; height: 0px;">
<script type="text/javascript" src="/javascripts/jquery.min.js?1329440016">
<script type="text/javascript" src="/javascripts/jquery.masonry.min.js?1327461530">
<script type="text/javascript" src="/javascripts/jquery.infinitescroll.min.js?1324335816">
<div class="item">

I'm using a combination of Masonry, Will Paginate, and Infinite Scroll. Masonry and Will Paginate are working fine but I can't seem to get the Infinite Scroll to work.

I have a feeling that it might be that my selectors are wrong but I am still in the dark after trying different variations.

Script

<script type="text/javascript">
 $(function(){

    var $container = $('#container');
    $container.imagesLoaded( function(){
      $container.masonry({
        itemSelector : 'item'
      });

    });

  });

// infinitescroll() is called on the element that surrounds 
// the items you will be loading more of
  $('#container').infinitescroll({

    navSelector  : '.pagination',            
                   // selector for the paged navigation (it will be hidden)
    nextSelector : '.pagination .next_page a',    
                   // selector for the NEXT link (to page 2)
    itemSelector : '#container .item'         
                   // selector for all items you'll retrieve
    },
    // trigger Masonry as a callback
    function ( newElements ) {
        var $newElems = $( newElements );
        $container.masonry( 'appended', $newElems );
    }
  );

</script> 

Navigation

<div class="pagination">
<span class="previous_page disabled">← Previous</span>
     <em>1</em>
     <a href="/?page=2" rel="next">2</a>
     <a href="/?page=3">3</a>
     <a href="/?page=4">4</a>
     <a href="/?page=5">5</a>
     <a href="/?page=6">6</a>
     <a href="/?page=7">7</a>
     <a class="next_page" href="/?page=2" rel="next">Next →</a>
</div>

Content

<div id="container" class="masonry" style="position: relative; height: 0px;">
<script type="text/javascript" src="/javascripts/jquery.min.js?1329440016">
<script type="text/javascript" src="/javascripts/jquery.masonry.min.js?1327461530">
<script type="text/javascript" src="/javascripts/jquery.infinitescroll.min.js?1324335816">
<div class="item">

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

油焖大侠 2025-01-14 22:51:16

尝试将无限滚动移动到里面。即,尝试以下操作:

$(function(){
...

  $('#container').infinitescroll({
    ...
  );
});

希望有帮助。

Try moving your infinitescroll inside. Namely, try the following:

$(function(){
...

  $('#container').infinitescroll({
    ...
  );
});

Hope that helps.

情感失落者 2025-01-14 22:51:16

您的 nextSelector 需要是 .pagination a.next_page,而不是 .pagination .next_page a

Your nextSelector needs to be .pagination a.next_page, not .pagination .next_page a.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文