同位素 + WordPress - 帖子加载后重新布局


Isotope + Wordpress - re-layout after posts load?

我在WordPress中使用带有砖石布局的Isotope,以及ImagesLoaded。每个帖子都是一个单独的同位素项目。一切似乎都运行良好,除了当我在帖子中加载动态内容时,例如 Twitter 小部件或嵌入式视频。项目的初始高度是在帖子/小部件加载之前设置的。一旦它完全加载,我需要同位素再次重新布局以适应新的高度。

有没有办法在所有帖子完全加载后再次调用布局函数?

这是我的同位素代码:

// init isotope
var $container = $('#cards');
$container.isotope({
    itemSelector: '.item',
    masonry: {
       columnWidth: '.grid-sizer',
       isFitWidth: true
    }
});

// layout Isotope again after all images have loaded
$container.imagesLoaded( function() {
  $container.isotope('layout');
});  

// infinite scroll
$container.infinitescroll({
        navSelector  : '.pagination',   
        nextSelector : '.pagination a', 
        itemSelector : '.item-scroll', 
        behavior: "twitter",
        loading: {
            finishedMsg: 'No more pages to load.'      
          }
        },     
        function ( newElements ) {
          var $newElems = jQuery( newElements ).hide(); // hide to begin with
          // ensure that images load before adding to masonry layout
          $newElems.imagesLoaded(function(){
            $newElems.fadeIn(); // fade in when ready
            $container.isotope( 'appended', $newElems );  
          });
        }    
      );
function onLayout() {
        $container.infinitescroll('scroll');
  }

感谢您的帮助!

试试这个:

 var $container = $('#cards');
$container.imagesLoaded( function() {
  // init isotope
$container.isotope({
itemSelector: '.item',
masonry: {
   columnWidth: '.grid-sizer',
   isFitWidth: true
}
});
});  

// infinite scroll
$container.infinitescroll({
    navSelector  : '.pagination',   
    nextSelector : '.pagination a', 
    itemSelector : '.item-scroll', 
    behavior: "twitter",
    loading: {
        finishedMsg: 'No more pages to load.'      
      }
    },     
    function ( newElements ) {
      var $newElems = jQuery( newElements ).hide(); // hide to begin with
      // ensure that images load before adding to masonry layout
      $newElems.imagesLoaded(function(){
        $newElems.fadeIn(); // fade in when ready
        $container.isotope( 'appended', $newElems ).isotope('layout');  
      });
    }    
  );
function onLayout() {
    $container.infinitescroll('scroll');
}