Skip to content

Instantly share code, notes, and snippets.

@patriziosotgiu
Created August 25, 2015 18:44
Show Gist options
  • Save patriziosotgiu/89325b0aa0e32fde207d to your computer and use it in GitHub Desktop.
Save patriziosotgiu/89325b0aa0e32fde207d to your computer and use it in GitHub Desktop.
jQuery - Check when all img and iframe of a div are loaded
// Get height of the block when all elements are loaded
// This fixes some bugs with lazyload in some browsers, and slow connections
var $elements = $('#div').find('img, iframe');
var elementsCount = $elements.length;
var loadedCount = 0;
$elements.on('load', function () {
loadedCount++;
if (loadedCount === elementsCount) {
getSetHeight();
}
});
@theDarji
Copy link

Nice one!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment