我将图像像一副纸牌一样堆叠在一起,并且每个图像的 z-Index 通过下面的代码依次更改,因此最终结果是动画。但是,它是线性的并且不会颠倒顺序,我希望它能够向前和向后设置动画。我不想要代码,但我确实想要知道可以做什么。我最终会想出代码=)
var imageArray = [];
function placeImage(x) {
var div = document.getElementById("div_picture");
div.innerHTML = ""; // clear images
for (counter=1;counter<=x;counter++) {
var image=document.createElement("img");
image.src="bola/bola"+counter+".png";
image.width="500";
image.height="500";
image.alt="bola"+counter;
image.id="imagem"+counter;
image.style.backgroundColor="rgb(255,255,255)"
image.style.position="absolute";
image.style.zIndex=counter;
div.appendChild(image);
imageArray[counter-1] = document.getElementById("imagem"+counter);
}
};
var imageShuffle = function(x) {
imageArray[x-1].style.zIndex=0;
for (counter=0;counter<x;counter++) {
imageArray[counter].style.zIndex++;
}
imageArray.splice(0, 0, imageArray[x-1]);
imageArray.pop();
};
window.onload = function() {
placeImage(14);
document.getElementById("div_picture").onclick=function() {setInterval("imageShuffle(14)",1000/14)};
};