เพื่อตั้งค่า fill mode สำหรับแอนิเมชัน ให้ใช้คุณสมบัติ animation-fill-mode ค่าที่มี: forwards, backwards, both (ทั้งสองทิศทาง)
ตัวอย่างโค้ด
ลองรันโค้ดด้านล่างเพื่อตั้งค่า 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: forwards;
}
@keyframes myanim {
from { left: 0px; background-color: green; }
to { left: 200px; background-color: blue; }
}
</style>
</head>
<body>
<div></div>
</body>
</html>
สรุปค่า fill-mode:
none(ค่าเริ่มต้น) - ไม่คงสไตล์ keyframe ใดๆforwards- คง keyframe สุดท้ายหลังจบbackwards- คง keyframe แรกก่อนเริ่ม (ระหว่าง delay)both- คงทั้ง keyframe แรกและสุดท้าย