jquery - Optimal process to append dynamically loaded items to Masonry -


i using masonry , imagesloaded prepare grid layout each item in grid dynamically added image. furthermore infinite scroll being used add in items subsequent pages on scroll (not manually triggered). provided below structure of grid item.

<article class="entry">   <a href="#" class="thumbnail-wrap">    </a>   <div class="entry-body">    <div class="photo-wrap">     <img src="..." alt="...">    </div>    <div class="photo-wrap">     <img src="..." alt="...">    </div>    <div class="photo-wrap">     <img src="..." alt="...">    </div>   </div> </article> 

the <div class="entry-body"></div> hidden via css. first image added via js inside "thumbnail-wrap" container. prevent throwing grid off-balance when new content loaded through infinite scroll newly loaded elements first hidden, images dynamically added inside "thumbnail-wrap", next items appended masonry , after elements shown. below js code used inside infinite scroll callback.

function(newelements){   var $newelems = $( newelements ).css({     opacity: 0   });   $newelems.imagesloaded(function(){     // first image being added     $newelems.each( function() {       var thumbnailimage = $(this).find('.entry-body .photo-wrap:first-child').html();       $(this).find(".thumbnail-wrap").append(thumbnailimage);     });     // newly loaded elements being appended     $grid.masonry( 'appended', $newelems, { // var $grid = $('#content');       isanimated: false       }, function(){         $newelems.animate({           opacity: 1       });     });   }); 

by physically placing code dynamically add images before appending them masonry trying prevent undue overlap of items. my question is, if efficient way go problem or there solution more optimal being used now?

any clarification in matter appreciated. thank you!


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -