首页 > 解决方案 > 如何使javascript动画第二次工作

问题描述

我有一个触发动画的功能

function jumpAnimation() {
  $('.array__elem').each(function (index) {
    $(this).css({
      animation: `jump 1s ease-in-out`,
      'animation-delay': index * 0.05 + 's',
    });
  });
}

但是,该函数仅在我第一次调用它时才起作用。当我再次调用该函数时,动画不会重新触发。我怎样才能做到这一点?

标签: javascripthtmljquerycss

解决方案


尝试添加css,animation: `jump 1s infinite ease-in-out`

如果这不起作用,您也可以尝试animation-iteration-count: infinite;

所以应该看起来像

function jumpAnimation() {
  $('.array__elem').each(function (index) {
    $(this).css({
      animation: `jump 1s infinite ease-in-out`,
      'animation-delay': index * 0.05 + 's',
    });
  });
}

推荐阅读