替代img src的jQuery回调? [英] jQuery callback on img src replacement?

查看:161
本文介绍了替代img src的jQuery回调?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要做的是,当用户将鼠标悬停在其缩略图上时,更改网页上的图像.对我来说,这样做很容易,因为缩略图src仅在文件名后附加了"tn_",否则是相同的.

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.

我遇到的问题是,当我在图像上切换src时,attr函数几乎立即返回img dom元素,而图像本身直到新图像加载时才改变.我想进行某种回调,以便我可以更改光标以显示加载符号,或者在加载新图像时在页面上的某处写入加载内容.

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.

我该怎么做?

推荐答案

您可以为图像提供 load() 回调.

You can give the image a load() callback.

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

这篇关于替代img src的jQuery回调?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆