【问题标题】:Rails 4 will_paginate masonryRails 4 will_paginate 砌体
【发布时间】:2014-08-14 08:56:43
【问题描述】:

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

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

【问题讨论】:

    标签: javascript jquery ruby-on-rails masonry


    【解决方案1】:
     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();
        });
    
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-25
      • 1970-01-01
      • 2023-03-26
      • 1970-01-01
      • 2019-05-29
      • 2015-10-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多