简体   繁体   English

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

[英]Infinite scroll not working with Will Paginate and Masonry

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. Masonry和Will Paginate都可以正常工作,但我似乎无法使Infinite Scroll正常工作。

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">

您的nextSelector必须是.pagination a.next_page ,而不是.pagination .next_page a

Try moving your infinitescroll inside. 尝试将无限滚动移动到内部。 Namely, try the following: 即,尝试以下操作:

$(function(){
...

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

Hope that helps. 希望能有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM