jQuery检查图像是否已加载 [英] jQuery check if image is loaded
本文介绍了jQuery检查图像是否已加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要帮助以下代码不起作用:
I need help with the following code which doesn't work:
var timeoutID=0;
var currentImage=0;//first image is position 0 in arrImages array
var arrImages=[bla bla bla array of image URLs];
function slideShow()
{
if($('#myImg').complete)// <------- Here is where it fails as that's UNDEFINED.
{
//curentImage is a global var that remebembers the on-screen image array key
var nextImage=currentImage+1;
//arrImages is the array of image URLs
if(nextImage>=arrImages.length){nextImage=0;}
$('#myImg').attr('src',nextImage);
clearTimeout(timeoutID);
//Change image each second after previous image was loaded
timeoutID=setTimeout("slideShow()",1000);
}
else
{
$('#myImg').load(slideShow);
}
}
基本上我想每秒更改#myImg的src,前提是计数器启动加载图像后。
Basically I want to change the src for #myImg each second, provided that the counter starts after the image loaded.
* 我讨厌Stack Overflow文本编辑器中的代码按钮!
推荐答案
'complete'用于原生javascript对象。所以你应该从jQuery获取javascript对象。
like,
'complete' is for native javascript object. so you should get javascript object from jQuery. like,
$('#myImg')[0].complete
或
$('#myImg').get(0).complete
这篇关于jQuery检查图像是否已加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文