jquery masonry images are overlapping until a page resize is done

瘦欲@ 提交于 2019-12-03 06:00:15

Use imagesLoaded() to triggered masonry after all images are loaded. (imagesLoaded() is provided by the script http://github.com/desandro/imagesloaded.)

$('.gallery-masonry').imagesLoaded( function(){
  $('.gallery-masonry').masonry({
   itemSelector: '.item',
   isAnimated: true,
   isFitWidth: true
  });
});

The accepted answer has missing steps. So here is a step-by-step.

  1. Go to the imagesloaded repo and download the minified version at https://github.com/desandro/imagesloaded/blob/master/imagesloaded.pkgd.min.js.
  2. Add that library to your project.
  3. At the bottom of your page call the file

```[Adjust path to your javascript files]

<script src="/js/masonry.pkgd.min.js"></script>
<script src="/js/imagesloaded.pkgd.min.js"></script>

<script>
  $('.gallery-masonry').imagesLoaded( function(){
    $('.gallery-masonry').masonry({
     itemSelector: '.item',
     isAnimated: true,
     isFitWidth: true
    });
  });
</script>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!