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

กำหนดหน่วงเวลาเริ่มต้น Animation ด้วย 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 วินาที ก่อนเริ่มแอนิเมชัน ค่าลบได้: animation-delay: -1s เริ่มทันทีแต่จากจุด 1 วินาทีของแอนิเมชัน (ข้ามส่วนแรกไป) เหมือน ID 1004062770