Created
May 10, 2011 15:45
-
-
Save thinkt4nk/964713 to your computer and use it in GitHub Desktop.
Dynamic Image Loading with jquery
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
// load an image - with a callback on load | |
function loadImageDynamic(image_url,callback,container) { | |
if( container != 'undefined' ) { | |
container = 'body'; | |
} | |
var image_load = 0; | |
$('<img/>') | |
.attr('src',image_url) | |
.load( function(e) { | |
if( image_load < 1 ) { // webkit hack to protect from multiple loads on cached images | |
image_load++; | |
callback(e); | |
} | |
}) | |
.appendTo(container); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment