开发者

jQuery callback on img src replacement?

开发者 https://www.devze.com 2023-01-22 10:43 出处:网络
What I am trying to do is to change an image on my webpage when the user mouses over a thumbnail of it. It is easy for me to do it this was b开发者_如何学Goecause the thumbnail src only has \'tn_\' ap

What I am trying to do is to change an image on my webpage when the user mouses over a thumbnail of it. It is easy for me to do it this was b开发者_如何学Goecause the thumbnail src only has 'tn_' appended to the filename and is otherwise identical.

The problem I'm having is that when I switch the src on the image the attr function returns the img dom element almost instantly while the image itself does not change until the new image loads. I want to have some sort of a callback, so that I can either change the cursor to show a loading symbol, or write loading somewhere on the page while the new image is loading.

How can I do this?


You can give the image a load() callback.

$('#imageID').load(function() { .... });
0

精彩评论

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