Isotope display gallery after images loaded

孤街浪徒 提交于 2019-12-01 20:49:35

问题


I tried to search and see if there was anything listed under this but I didn't see anything. I have a gallery thats laid out using Isotope and it works fine, but while the page loads, the images in the gallery are displayed down the middle of the page and then once they are loaded jump to their respective positions.

I'm trying to figure out a way to set the container to hide until the images are in their spots and then fade them in with $container.fadeIn(1000);

I just don't know how to trigger that function after they are loaded. I've tried using Document.ready a few places and can't seem to get it react right.

<script>
$(function(){

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

  $container.imagesLoaded( function(){
    $container.isotope({
        layoutMode : 'fitRows',
        itemSelector : '.photo'
    }); 

  });

$container.fadeIn(1000);

});

This kind of works but it isn't really listening for the images to be fully loaded yet.


回答1:


The plugin's author explains it on GitHub. It's pretty simple actually. Just add the fadeIn right before starting the isotope gallery.

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

$container.imagesLoaded( function(){
  $container.fadeIn(1000).isotope({
    layoutMode : 'fitRows',
    itemSelector : '.photo'
  });
});


来源:https://stackoverflow.com/questions/15177919/isotope-display-gallery-after-images-loaded

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!