Created
April 12, 2011 21:46
-
-
Save mde/916496 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 assertImageLoaded = function (img) { | |
var complete = img.complete; | |
// Workaround for Safari -- it only supports the | |
// complete attrib on script-created images | |
if (typeof complete == 'undefined' || complete === false) { | |
var test = new Image(); | |
// If the original image was successfully loaded, | |
// src for new one should be pulled from cache | |
test.src = img.src; | |
complete = test.complete; | |
} | |
// Check the complete attrib. Use strict equality | |
// check -- don't want undefined, null, etc. | |
// -------------------------- | |
// False -- Img failed to load in IE/Safari, or is | |
// still trying to load in FF | |
if (complete === false) { | |
return false; | |
} | |
// True, but image has no size -- image failed to // load in FF | |
else if (complete === true && | |
img.naturalWidth == 0) { return false; | |
} // Otherwise all we can do is assume image loaded | |
else { return true; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment