如何在调用函数时暂停动画

how to pause animation when function is called?

本文关键字:暂停 动画 函数 调用      更新时间:2023-09-26

我有一个移动的动画,但当用户单击按钮调用pause()函数时,我想暂停动画。不知道如何做到这一点,任何帮助都将不胜感激。

我所拥有的:

function pause() {
console.log("paused ok");
}

和html:

<img src="image1.gif" alt="img1" id="img1" style="width:300px;height:300px;">
<input id=pausebutton  class="button" type="button" value="Pause" name="pause_button"  onClick="pause()">

试试这个:

function pause() {
  console.log("paused ok");
  var animation = document.getElementById("img1");
  animation.pause();
}