我有一组“图像”,每个图像具有不同的Z-index。顶部的“卡片”会连续下到Z-index最低的卡片(我们称之为“image1”),直到“image1”出现在其他顶部。这是一个动画,但我无法让for循环迭代一段时间。我想在1秒内尝试30张图片。下面是代码:JavaScript - 用于堆叠图像的循环迭代延迟
function placeImage(x) {
var div = document.getElementById("div_picture_right");
div.innerHTML = ""; // clear images
for (counter=1;counter<=x;counter++) {
var image=document.createElement("img");
image.src="borboleta/Borboleta"+counter+".png";
image.width="195";
image.height="390";
image.alt="borboleta"+counter;
image.id="imagem"+counter;
image.style.backgroundColor="rgb(255,255,255)"
image.style.position="absolute";
image.style.zIndex=counter;
div.appendChild(image);
}
};
var animaRight = function(x) {
var imageArray = [];
for (counter=1;counter<=x;counter++) {
imageArray[counter-1] = document.getElementById("imagem"+counter);
}
function delayLoop(x) {
for (counter=imageArray.length;counter>1;counter--) {
if (imageArray[counter-1].style.zIndex==counter) {
imageArray[counter-1].style.zIndex-=counter;
setTimeout("delayLoop()", 1000/x);
}
}
}
delayLoop(x);
};
任何帮助我非常感谢!我尝试了一些setTimeout的功能,但我恐怕我做错了(安置,也许?)。如果你需要,我会用我试过的代码编辑代码。
没有你所尝试的,很难猜测你的问题,但也许这(有关问题)(http://stackoverflow.com/questions/14791158/javascript-settimeout-and-loops)将帮助? – 2013-02-26 14:31:01
我马上编辑!问题是,我尝试了很多方法,所以我必须选择一个。 – 2013-02-26 14:32:12