且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

jQuery:每隔5秒,自动点击一个列表中的下一个图像?

更新时间:2022-12-08 22:28:55

您可以轻松计算切换功能中的下一个图像。
这样你就不会弄乱你的var空间;)

You may easily calculate the next image within the switch function. This way you won't mess up your var space ;)

(function switchToImage(img) {
  $(img).click()
  var images = $('#thumbs img');
  var nextIndex = ($.inArray(images, img) + 1) % images.length;
  setTimeout(function() { 
    switchToImage(images[nextIndex]) 
  }, 5000);
})($('#thumbs img')[0]);