admin管理员组文章数量:1221307
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')plete)// <------- 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); } }
Basically I want to change the src for #myImg each second, provided that the counter starts after the image loaded.
*I hate the code button in the text editor for Stack Overflow!
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); } }
Basically I want to change the src for #myImg each second, provided that the counter starts after the image loaded.
*I hate the code button in the text editor for Stack Overflow!
Share Improve this question edited Mar 23, 2011 at 11:24 Francisc asked Mar 23, 2011 at 11:12 FranciscFrancisc 80.4k65 gold badges185 silver badges278 bronze badges 4 |2 Answers
Reset to default 16'complete' is for native javascript object. so you should get javascript object from jQuery. like,
$('#myImg')[0].complete
or
$('#myImg').get(0).complete
If I remember correctly the image gets the width and height when it gets loaded. So I guess you could check the width if the image. And as long as that is 0 the image is not loaded.
本文标签: javascriptjQuery check if image is loadedStack Overflow
版权声明:本文标题:javascript - jQuery check if image is loaded - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1739337546a2158777.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
img.complete
andload
most of the time doesn't get fired unless you injectsrc
after attach event. – KJYe.Name Commented Mar 23, 2011 at 13:47