0

我正在尝试使用砖石进行无限滚动,但是当我加载更多内容时,这些框会附加到网格的开头并与其他框重叠。我在一些盒子里有图像。

显示.js.erb

var boxes = $('<%= j render(:partial => "mypost", :locals => {mypost: mypost}, :collection => mypost) %>')
var $container = $('#containermason');

$container.append($boxes).imagesLoaded(
    function(){
        $container.masonry('appended', $boxes);

    }
);

<% if mypost.next_page %>
  $('.pagination').replaceWith('<%= j will_paginate mypost %>');
<% else %>
  $('.pagination').remove();
<% end %>
4

1 回答 1

0
 Used the jquery.infinitescroll plugin instead, much simpler

 $(function(){

  var $container = $('#containermason');

  $container.imagesLoaded(function(){
    $container.masonry({
      itemSelector: '.item',
      columnWidth: '265px',
      "gutter": 10
    });
  });

  $container.infinitescroll({
    navSelector  : '.pagination',    // selector for the paged navigation 
    nextSelector : '.pagination a',  // selector for the NEXT link (to page 2)
    itemSelector : '.item',     // selector for all items you'll retrieve
    loading: {
      finishedMsg: '<p style="background: #82d63e; margin-bottom: 20px; padding: 5px; border-radius: 10px; color: #fff; font-weight: bold;">that\'s all the content</p>',
          img: 'http://i.imgur.com/C1U8WRZ.gif'
      }
    },
    // trigger Masonry as a callback
    function( newElements ) {
      // hide new items while they are loading
      var $newElems = $( newElements ).css({ opacity: 0 });
      // ensure that images load before adding to masonry layout
      $newElems.imagesLoaded(function(){
        // show elems now they're ready
        $newElems.animate({ opacity: 1 });
        $container.masonry( 'appended', $newElems, true ); 

      });
 $("abbr.timeago").timeago();
    });

});
于 2014-08-14T16:06:41.080 回答