I know that $(window).lo开发者_StackOverflowad
fires when all of the images on the page have loaded. I am looking to have something simular for when a specific image has been loaded to the page. Any help would be greatly appreciated.
See http://api.jquery.com/load-event/
E.g.
<img src="book.png" alt="Book" id="book" />
$('#book').load(function() {
// Handler for .load() called.
});
Update:
If the image is already loaded by the time a load handler is specified, the load handler will not be triggered. So it is best to specify the image source after setting the load handler.
<img id="book" />
...
$('#book').load(function() {
alert('loaded') ;
});
$('#book').attr('src','book.png') ;
You can bind the load event to images as well.
$('#myimage').load(function() {
console.debug('My image has loaded...');
});
精彩评论