jQuery callback on img src replacement?

非 Y 不嫁゛ 提交于 2019-12-11 04:47:10

问题


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 because 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?


回答1:


You can give the image a load() callback.

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


来源:https://stackoverflow.com/questions/4036865/jquery-callback-on-img-src-replacement

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!