加载后淡入图像
我正在尝试将图像加载到带有 fadeIn 效果的 div 中。问题是我不知道如何同时避免加载和褪色。我希望加载图像,并且在完全加载后,它应该淡入。
http://www. izrada-weba.com/vedranmarketic
这些是图像拇指:
<div id="thumbs">
<a href="#" class="slika_thumb" id="1"><img src="slike/th.jpg" border="0"/></a><a href="#" class="slika_thumb" id="2"><img src="slike/th.jpg" border="0"/></a><a href="#" class="slika_thumb" id="3"><img src="slike/th.jpg" border="0"/></a><a href="#"><img src="slike/th.jpg" border="0"/></a><a href="#"><img src="slike/th.jpg" border="0"/></a><a href="#"><img src="slike/th.jpg" border="0"/></a> </div>
</div>
这是应加载图像的容器:
<div id="desna_kolona">
<div id="slika"><img src="slike/c6.jpg" /></div>
</div>
这是 jquery 文件:
$(document).ready(function(){
$('.slika_thumb').click(function() {
var id = $(this).attr("id");
$('#slika').hide();
$.ajax({
url: 'slike/slika.php?id=' + id,
success: function(data) {
$('#slika').html(data);
$('#slika').fadeIn();
}
});
});
});
我尝试在 successcomplete
代码> 但结果仍然相同。 有什么建议吗?
I'm trying to make image being loaded into div with fadeIn effect. Problem is that I don't know how to avoid loading and fading at the same time. I want image to be loaded and after it is completely loaded it should be faded in.
http://www.izrada-weba.com/vedranmarketic
These are image thumbs:
<div id="thumbs">
<a href="#" class="slika_thumb" id="1"><img src="slike/th.jpg" border="0"/></a><a href="#" class="slika_thumb" id="2"><img src="slike/th.jpg" border="0"/></a><a href="#" class="slika_thumb" id="3"><img src="slike/th.jpg" border="0"/></a><a href="#"><img src="slike/th.jpg" border="0"/></a><a href="#"><img src="slike/th.jpg" border="0"/></a><a href="#"><img src="slike/th.jpg" border="0"/></a> </div>
</div>
This is container where image should be loaded:
<div id="desna_kolona">
<div id="slika"><img src="slike/c6.jpg" /></div>
</div>
and this is jquery file:
$(document).ready(function(){
$('.slika_thumb').click(function() {
var id = $(this).attr("id");
$('#slika').hide();
$.ajax({
url: 'slike/slika.php?id=' + id,
success: function(data) {
$('#slika').html(data);
$('#slika').fadeIn();
}
});
});
});
I tried to use complete
below success
but still the same result.
Any advice?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
也许尝试将 onload 处理程序绑定到通过 ajax 加载的数据内的任何图像。
Maybe try to bind an onload handler to any images inside the data which gets loaded via ajax.
正如您应该的那样,您一开始就隐藏了图像。我要做的就是向图像添加一个加载事件处理程序,然后运行 AJAX 来设置 HTML。在您的加载事件处理程序中,淡入图像。如果您只替换现有图像的源,那么您可以向其中添加加载处理程序,这会更容易 - 它不适用于 div。
You have the image hidden to start with, as you should. What I would do is add a load event handler to the image, then run your AJAX to set the HTML. In your load event handler, fade the image in. It will be easier if you just replace the source of the existing image since then you can add the load handler to it -- it won't work on the div.
使用图像对象加载图像。下载图像时它会触发
load
事件。因此,当图像下载 100% 时,将图像放入#slika
中并使用jQuery.fadeIn()
。Load images using Image Object. It fires
load
event when image is downloaded. So you put image into#slika
when it's 100% downloaded and usejQuery.fadeIn()
.您需要在 .html 事件上使用回调函数。
编辑:这实际上可能不起作用,因为 .html 是同步操作。您的意思是 load() 吗?
You need to use a callback function on the .html event.
edit: this actually may not work due to .html being a synchronous operation. Did you mean load() instead?
您必须对该图像发出 AJAX 请求,通过侦听成功事件来等待它完全加载。这将帮助您将图像放入浏览器缓存中。然后你就可以按照你的方式去做。此后图像将立即加载。
You must issue AJAX request for that image, wait for it to be loaded completely by listening on success event. This will help you to get the image into the browser cache. Then you can do it your way. The image will be loaded instantly after this.