gpt4 book ai didi

javascript - jQuery 检查图像是否加载

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:51:26 25 4
gpt4 key购买 nike

我需要有关以下不起作用的代码的帮助:

var timeoutID=0;var currentImage=0;//first image is position 0 in arrImages arrayvar 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,前提是计数器在图像加载后启动。

*我讨厌 Stack Overflow 文本编辑器中的代码按钮!

最佳答案

'complete' 用于 native javascript 对象。所以你应该从 jQuery 获取 javascript 对象。喜欢,

$('#myImg')[0].complete

$('#myImg').get(0).complete

关于javascript - jQuery 检查图像是否加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5404335/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com