Skip to content

Instantly share code, notes, and snippets.

@etyp
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save etyp/48f7e30181f715f3f8c6 to your computer and use it in GitHub Desktop.
Save etyp/48f7e30181f715f3f8c6 to your computer and use it in GitHub Desktop.
Image loads
var $bgImages = $('.background-image');
var loadCount = 0;
$bgImages.each(function (index) {
// Get source based on size
var src = isMobile() ? $(this).attr('data-mobile') : $(this).attr('data-desktop') ;
// Set source
this.src = src;
// On image load, call functions
$(this).on('load', function () {
// Increase load count
loadCount++;
// If this is the last loaded, do functions
if (loadCount === $bgImages.length) {
// Do your functions here
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment