在動畫未播放時,設定元素的 CSS 樣式


使用 animation-fill-mode 屬性設定元素在動畫不播放時的樣式

示例

即時演示

<!DOCTYPE html>
<html>
   <head>
      <style>
         div {
            width: 150px;
            height: 200px;
            position: relative;
            background: red;
            animation-name: myanim;
            animation-duration: 2s;
            animation-fill-mode: backwards;
         }
         @keyframes myanim {
            from {left: 0px; background-color: green;}
            to {left: 200px; background-color: blue;}
         }
      </style>
   </head>
   <body>
      <div></div>
   </body>
</html>

更新於: 2020-06-24

85 次瀏覽

開拓您的 職業生涯

透過完成課程獲得認證

開始
廣告
© . All rights reserved.