【问题标题】:How can I play/pause the animation in toggle class button?如何在切换类按钮中播放/暂停动画?
【发布时间】:2022-12-14 10:56:54
【问题描述】:

我尝试使用切换类按钮播放和暂停动画。你能给一些建议吗?

使用此代码,当我单击播放/暂停按钮时,动画不会暂停。

In my HTML file I write something like this:

<button type="submit" id="btn">play/Pause</button>

在我的 CSS 文件中,我写了这样的东西:

.mysun, .mysky   {
  animation-play-state: paused;
  };

在我的 JS 文件中,我写了这样的东西:

btn.onclick = myFunction;
function myFunction() {
  var sun = document.getElementById("sun");
  var sky = document.getElementById("sky");
  sun.classList.toggle("mysun");
  sky.classList.toggle("mysky");
};

【问题讨论】:

    标签: animation css-animations togglebutton


    【解决方案1】:

    试试 !important 旁边怎么样 sky.classList.toggle("mysky");?

    【讨论】:

      猜你喜欢
      • 2019-06-25
      • 2016-12-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多