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