小编Nik*_*hes的帖子

如何使用 jQuery 在第二次单击时反转 CSS 动画

我制作了以下菜单图标 CSS 动画,当我点击它时会触发它。当我使用 jQuery 第二次单击它时,我想让它反向动画。

#path1 {
  stroke-dasharray: 33px;
  stroke-dashoffset: 33px;
  animation: line 1.5s linear forwards;
  animation-play-state: paused;
}

@keyframes line {
  100% {
    stroke-dashoffset: -15.5;
  }
}

#halfLineLeft {
  transform-origin: 1% 50%;
  animation: shrinkleft 1s linear forwards;
  animation-play-state: paused;
}

 #halfLineRight {
  transform-origin: 100% 1%;
  animation: shrinkleft 1s linear forwards;
  animation-play-state: paused;
}

@keyframes shrinkleft {
  100% {
    transform: scale(0,1);
  }
}
svg {
  transform: translate(350px, 200px);
}
Run Code Online (Sandbox Code Playgroud)

这是我到目前为止的 jQuery ......

$("svg").click(
  function(){
     $("#path1, #halfLineLeft, #halfLineRight").css("animation-play-state", "running");
  }
 ); …
Run Code Online (Sandbox Code Playgroud)

css jquery animation reverse function

5
推荐指数
1
解决办法
1379
查看次数

标签 统计

animation ×1

css ×1

function ×1

jquery ×1

reverse ×1