Skip to content

Instantly share code, notes, and snippets.

@zmajstor
Last active August 29, 2015 13:56
Show Gist options
  • Save zmajstor/9174680 to your computer and use it in GitHub Desktop.
Save zmajstor/9174680 to your computer and use it in GitHub Desktop.
how to wait for jQuery .append to finsh
<div class="card">
<%= image_tag (collection.designer.cover_image_url), class: "center-block" %>
<div class="card-hover">
<span class="card-overlay">
<%= collection.designer.fullname %><br>
<%= collection.designer.live_collection.name %><br>
<%= collection.designer.location %>
</span>
</div>
</div>
...
<div class="container card-container text-center" id="masonry-card-container">
<%= render @collections %>
</div>
...
var $masonryContainer = $('#masonry-card-container');
var $newItems = $('<%= escape_javascript render(@collections) %>');
$masonryContainer.append($newItems.hide());
$masonryContainer.waitForImages(function() {
// All descendant images have been loaded
setTimeout(function(){
// Action after append
$newItems.show();
$masonryContainer.isotope( 'appended', $newItems );
}, 50);
});
var $container = $('#masonry-card-container');
$( window ).load(function() {
$container.isotope({
itemSelector: '.card',
layoutMode: 'masonry',
masonry: { gutter: 5 }
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment