简体   繁体   English

Rails 4 will_paginate砌体

[英]Rails 4 will_paginate masonry

I'm trying to get infinite scroll working with masonry but when I load more content, the boxes are appended to beginning of grid and overlap others. 我试图使无限滚动处理砖石结构,但是当我加载更多内容时,这些框会附加到网格的开头并与其他网格重叠。 I have images in some of the boxes. 我在某些盒子里有图像。

show.js.erb show.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 %>
 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();
    });

});

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

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