加载所有图像时的jquery div [英] jquery div when all images loaded
本文介绍了加载所有图像时的jquery div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以通过以下方式加载图片:
I can load an image when it is loaded, by doing:
<img style="display:none;" src="big3.jpg">
<script type="text/javascript">
$('img').load(function(){
$(this).css({'display':'block'})
});
</script>
但我想要的是在加载所有img时加载div,但这不起作用,为什么? :
But what I want is to load the div when all img is loaded, but this is not working, why? :
<div style="display:none;">
<img src="big3.jpg">
</div>
<script type="text/javascript">
$('div').load(function(){
$(this).css({'display':'block'})
});
</script>
推荐答案
正如@Kolink所说,div不加载。当div中的所有图像都已加载时,此代码将显示div。 (未经测试)
As @Kolink said, divs don't load. This code will show the div when all the images inside the div have loaded. (untested)
var $images = $('div img');
var loaded_images_count = 0;
$images.load(function(){
loaded_images_count++;
if (loaded_images_count == $images.length) {
$("div").show();
}
});
这篇关于加载所有图像时的jquery div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文