jQuery图像准备就绪时会逐渐淡入 [英] jQuery images fade-in on ready
问题描述
我目前正在处理一个包含非常大图像的项目.为了在加载图像时产生平滑的淡入效果,我尝试在jQuery 1.9.1中使用ready(),但是由于某些原因,它无法正常工作,并且在加载图像之前会显示图像.
I'm currently working on a project with some very large images. To make a smooth fade-in effect when an image has been loaded, i tried to use ready() with jQuery 1.9.1, but for some reason it doesn't work and shows images before it has been loaded.
$("img").ready(function(){
$(this).fadeIn("slow");
});
我在做什么错?
谢谢!我使用了Adeneo的方法: http://jsfiddle.net/hAm65/
Thank you! I got it working with Adeneo's method: http://jsfiddle.net/hAm65/
推荐答案
仅来自 DOCS 该文档有一个就绪事件:
From the DOCS, only the document has a ready event:
.ready()方法只能在与当前文档匹配的jQuery对象上调用.
The .ready() method can only be called on a jQuery object matching the current document.
您可以尝试更多类似的方法:
You can try something more like this:
$("img").each(function(i,el){
var img = new Image();
img.onload = function() {
$(el).fadeIn("slow");
}
img.src = el.src;
});
这篇关于jQuery图像准备就绪时会逐渐淡入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!