[英]How do I make a jQuery loop which changes the href attribute of a link?
I've built a slideshow gallery from scratch using jQuery
. 我已经使用
jQuery
从头开始构建了幻灯片库。 It can have any number of slides. 它可以有任意数量的幻灯片。 Under the slideshow I have a 'More info' button.
在幻灯片下方,我有一个“更多信息”按钮。 I would like this link to change every 5000ms to reflect the slide being show.
我希望此链接每隔5000ms更改一次,以反映正在显示的幻灯片。
I know I can use .attr
to change the href
value itself, it is just changing it at intervals of 5000ms to different things (on a loop!) that I'm completely at a loss with... 我知道我可以使用
.attr
来更改href
值本身,它只是以5000ms的间隔将其更改为不同的内容(循环!),我完全不知所措...
Help would be greatly appreciated! 帮助将不胜感激!
//Set Image to first picture by default.
$('#yourImageId').attr("src", imageSrcArray[0]);
var milliseconds = 5000;
//Call Function after 5 seconds to show second picture
var t=setTimeout("changeSlide();", milliseconds);
//If you set the image's original src to your first array item, this will cause the first update in 5 seconds to display the second item.
var cnt=1;
function changeSlide(){
//update image src
$('#yourImageId').attr("src", imageSrcArray[cnt]);
t=setTimeout("changeSlide();", milliseconds);//Call Function Again after 5 seconds
cnt++;
//Check that cnt is within image array bounds
if (cnt > imageSrcArray.length-1) cnt=0;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.