gpt4 book ai didi

Javascript - 图像不循环/旋转

转载 作者:行者123 更新时间:2023-12-02 19:58:18 31 4
gpt4 key购买 nike

我正在编写一个脚本,用于在 javascript 中旋转/循环浏览图像,同时遵守循环浏览图像的次数限制。我所拥有的如下:

<a id="imageurl"><img id="Rotating1" border="0"></img></a>

<script language="JavaScript">

var delay = 3000; //6000 = change to next image after 6 seconds
var cycles = 2;
var currentCycle = 0;

function RotateImages(Start, delay)
{
var a = new Array("frown.gif","grim.gif","smile.gif", "bomb.gif");
var c = new Array("url1", "url2", "url3", "url4");
var b = document.getElementById('Rotating1');
var d = document.getElementById('imageurl');
var totalCycles = cycles * a.length;
// alert ("currentCycle: " + currentCycle);
// alert ("totalCycles: " + totalCycles);

if (Start>=a.length)
Start=0;
b.src = a[Start];
d.href = c[Start];

if (currentCycle < totalCycles) {
window.setTimeout("RotateImages(" + (Start+1) + ")", delay);
currentCycle++;
}
}

RotateImages(0, delay);

</script>

当我取消注释警报框时,脚本的行为就像它正在工作一样。当我注释掉它们时,旋转似乎停止了。关于到底发生了什么以及如何解决它有什么想法吗?

谢谢!

最佳答案

也许您想更改此行:

window.setTimeout("RotateImages(" + (Start+1) + ")", delay);

进入:

window.setTimeout("RotateImages(" + (Start+1) + ", " + delay + ")", delay);

这样下次调用RotateImages时,它将保持延迟。

关于Javascript - 图像不循环/旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8351007/

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