Last active
August 29, 2015 14:00
-
-
Save asafge/11218826 to your computer and use it in GitHub Desktop.
JS - Wait for an image to load by periodically checking it's status. Useful when images are cached, and some browsers don't trigger appropriate events.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var $img = ..., | |
imagesLoadedCallback = function() { | |
// Do stuff | |
} | |
(function waitForImageLoaded() { | |
if ($img[0].complete && $img[0].naturalWidth > 0) { | |
imagesLoadedCallback(); | |
} | |
else { | |
setTimeout(waitForImageLoaded, 300); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment