<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
*{
margin: 0;
padding: 0;
}
img{
width: 64px;
height: 128px;
position: absolute;
}
</style>
</head>
<body>
<img id="fish" src="img/3/0.png" style="top: 500px; left: 400px;" />
</body>
<script>
var images = [];
for(var i=0;i<=11;i++){
images[i] = 'img/3/' + i + '.png';
}
//console.log(images);
var fish = document.getElementById('fish');
var index = 0;
setInterval(function(){
index++;
// 如果图片下标的位置大于图片数组的长度,重置为0
if (index >= images.length){
index = 0;
}
fish.src = images[index];
fish.style.top = parseInt(fish.style.top) + -1 + 'px';
}, 1000/10);
</script>
</html>
部分图片资料: