ใช้คุณสมบัติ animation-direction เพื่อรันแอนิเมชันในทิศทางถอยหลัง ค่าที่ใช้คือ reverse
ตัวอย่างโค้ด
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 150px;
height: 200px;
background-color: yellow;
animation-name: myanim;
animation-duration: 2s;
animation-direction: reverse;
}
@keyframes myanim {
from { background-color: green; }
to { background-color: blue; }
}
</style>
</head>
<body>
<div></div>
</body>
</html>
คำอธิบาย: animation-direction: reverse ทำให้แอนิเมชันเริ่มจาก keyframe สุดท้าย (to) ไปยัง keyframe แรก (from) กลับกันกับปกติ คือเริ่มจากสีน้ำเงิน แล้วเปลี่ยนเป็นสีเขียว