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

คุณสมบัติ CSS animation-iteration-count

ใช้คุณสมบัติ animation-iteration-count เพื่อกำหนดจำนวนครั้งที่แอนิเมชันควรเล่น

ตัวอย่างโค้ด

ลองรันโค้ดด้านล่างเพื่อทดสอบ animation-iteration-count property:

<!DOCTYPE html>
<html>
<head>
  <style>
    div {
      width: 150px;
      height: 200px;
      position: relative;
      background-color: yellow;
      animation-name: myanim;
      animation-duration: 2s;
      animation-direction: alternate-reverse;
      animation-iteration-count: 3;
    }
    @keyframes myanim {
      from { left: 100px; }
      to { left: 200px; }
    }
    #demo1 { animation-timing-function: ease; }
    #demo2 { animation-timing-function: ease-in; }
  </style>
</head>
<body>
  <div id="demo1">ease effect</div>
  <div id="demo2">ease-in effect</div>
</body>
</html>

คำอธิบาย: animation-iteration-count: 3 รัน 3 รอบ ร่วมกับ alternate-reverse ทำให้สลับทิศทาง โค้ดตัวอย่างมี 2 div แสดง timing-function ต่างกัน (ease และ ease-in) แต่ iteration-count เหมือนกัน