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

วิธีหน่วงเวลา Animation ด้วย CSS

เพื่อหน่วงเวลาแอนิเมชัน ให้ใช้คุณสมบัติ 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>

คำอธิบาย: animation-delay: 2s ทำให้แอนิเมชันเริ่มหลังจากโหลดหน้าเว็บไปแล้ว 2 วินาที ค่าลบได้ เช่น -1s จะเริ่มทันทีแต่จากจุดที่ 1 วินาทีของแอนิเมชัน