开发者

Jquery on specific image load

开发者 https://www.devze.com 2023-03-05 13:44 出处:网络
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 h

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...');
});
0

精彩评论

暂无评论...
验证码 换一张
取 消