jquery masonry images are overlapping until a page resize is done

前端 未结 2 1886
情深已故
情深已故 2021-02-08 04:54

I\'ve found this template that demonstrates the issue I\'m having with jquery masonry and image layout. Take a look at this twitter bootstrap template page:

The very fi

相关标签:
2条回答
  • 2021-02-08 05:24

    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
      });
    });
    
    0 讨论(0)
  • 2021-02-08 05:25

    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>
    
    0 讨论(0)
提交回复
热议问题