我有一个开门的动画(41 帧),我想使用 javaScript 让它在 onmouseover 上打开,我希望它回到第 1 帧 onmouseout。我认为我在 onmouseout 部分做得不太对。在此先感谢您的帮助!
HTML:
<div onmouseover="startAnimation()" onmouseout="stopAnimation()" id="door2"></div>
<div id="door">
<img src="images/Animation_Door/0001.png">
<img src="images/Animation_Door/0002.png">
<img src="images/Animation_Door/0003.png">
...etc...(41 frames)
css:
#door img{
display: none;
}
#door img:first-child {
display: block;
}
javaScript:
function startAnimation() {
var frames = document.getElementById("door").children;
var frameCount = frames.length;
for (i=0; i<41; i++) {
setTimeout(function(){
frames[i % frameCount].style.display = "none";
frames[++i % frameCount].style.display = "block";
}, 50*i);
}
}
function stopAnimation() {
var frames = document.getElementById("door").children;
var frameCount = frames.length;
for (i=0; i<1; i++){
setTimeout(function(){
frames[++i % frameCount].style.display = "none";
frames[i % frameCount].style.display = "block";
}, 50*i);
}
}