Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

About loading images using masonry.js

recently, I write a project which needs to load items like "pinterest". so i use masonry -- a jquery plugin.

but the problem is, the plugin runs after all the images are loaded, because it needs to calculate the size of the items and reposition them. that leads to a problem is: if the images fail to load, then the plugin will not run or calculate in the wrong way. anybody has experience with it that can give me a help?

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

$container.imagesLoaded( function(){

  $container.masonry({

    itemSelector : '.each_tweet'

  });

  $('.fancy img').each(function(){

    var $this = $(this),

        url = $this.attr('alt');

    $this.attr('src',url);

  });

});

Thank you !

like image 692
Bryant Avatar asked May 18 '26 21:05

Bryant


1 Answers

I found the solution: to use lazy load images to load a blank image first. after all images loaded then re-trigger the masonary

like image 90
Bryant Avatar answered May 22 '26 00:05

Bryant



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!