使用 CSS 先向後,再向前執行動畫


使用 animation-direction 屬性可以先向後,再向前回放動畫。此屬性與 alternate-reverse 動畫效果一同使用,可以實現這一效果。

示例

即時演示

<!DOCTYPE html>
<html>
   <head>
      <style>
         div {
            width: 150px;
            height: 200px;
            position: relative;
            background-color: yellow;
            animation-name: myanim;
            animation-duration: 2s;
            animation-direction: alternate-reverse;
            animation-iteration-count: 3;
         }
         @keyframes myanim {
            0% {background-color:green; left:0px; top:0px;}
            50% {background-color:maroon; left:100px; top:100px;}
            100% {background-color:gray; left:0px; top:0px;}
         }
      </style>
   </head>
   <body>
      <div></div>
   </body>
</html>

更新於:2020 年 6 月 24 日

2K+ 瀏覽量

開啟您的職業生涯

完成課程,獲得認證

開始學習
廣告
© . All rights reserved.