改变img标签的src属性后触发效果
我使用此代码更改图像标签的 src 属性(使用原型和 scriptaculous):
new Effect.Fade("images",{afterFinish:
function()
{
$("detail").setAttribute("src", "img/02.jpg");
new Effect.Appear("images",{duration:0.8});
}
});
其中“images”是容器(div),“detail”是 img 标签 结果是当前图像消失,出现,然后新图像突然出现。 我的问题是,如何检查新图像是否已被浏览器完全加载以触发 Effect.Appear? 还有其他方法可以做到这一点吗?
Im using this code to change the src attribute of an image tag (using prototype and scriptaculous):
new Effect.Fade("images",{afterFinish:
function()
{
$("detail").setAttribute("src", "img/02.jpg");
new Effect.Appear("images",{duration:0.8});
}
});
Where "images" is the container (a div) and "detail" is the img tag
The result is the current image fades, appears and then the new image suddenly shows.
My question is, how can i check the new image is fully loaded by the browser to trigger the Effect.Appear after?
Is there another way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
图像有一个可以连接的
onload
事件:根据我的经验,它有时有点不稳定(有时似乎没有被执行)。最好预加载图像并仅在加载完整文档后才允许此效果(
onload
而不是dom:load
或ready
)。Images have an
onload
event you can hook up to:In my experience, it is a bit flaky sometimes (at times doesn't seem to get executed). It would be better to pre-load the image and allow this effect only after the full document has loaded (
onload
instead ofdom:load
orready
).替换
为
要告诉用户您正在加载图像,您可以为图像设置一个 css 背景,带有旋转圆圈或任何适合的背景。
Replace
with
To tell the user that you are loading the image, you could set a css background to the image, with a spinnging circle or whatever suits.