Skip to content

Instantly share code, notes, and snippets.

@thinkt4nk
Created May 10, 2011 15:45
Show Gist options
  • Save thinkt4nk/964713 to your computer and use it in GitHub Desktop.
Save thinkt4nk/964713 to your computer and use it in GitHub Desktop.
Dynamic Image Loading with jquery
// 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