Computer >> คอมพิวเตอร์ >  >> การเขียนโปรแกรม >> CSS

ด้วย 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>