Thuộc tính animationIterationCount được sử dụng để thiết lập hoặc lấy số lần hoạt ảnh sẽ phát.
Cú pháp
Sau đây là cú pháp cho -
Đặt thuộc tính animationIterationCount -
object.style.animationIterationCount = "number|infinite|initial|inherit"
Giá trị
Sau đây là các giá trị -
| Sr.No | Giá trị &Mô tả |
|---|---|
| 1 | số Giá trị số cho biết số lần hoạt ảnh sẽ được phát. Nó được đặt thành 1 theo mặc định. |
| 2 | vô hạn Điều này làm cho hoạt ảnh để chơi vô hạn. |
| 3 | ban đầu Để đặt thuộc tính này thành giá trị ban đầu. |
| 4 | inherit Để kế thừa giá trị tài sản mẹ. |
Ví dụ
Chúng ta hãy xem một ví dụ cho thuộc tính animationIterationCount -
<!DOCTYPE html>
<html>
<head>
<style>
p {
color: black;
animation: shrink 3s;
animation-timing-function: ease;
animation-iteration-count: 1;
}
@keyframes shrink {
0% {
color: white;
letter-spacing: 1.8em;
}
100% {
color: magenta;
letter-spacing: 0.01em;
}
}
</style>
<script>
function IncreaseIteration(){
document.getElementById("PARA1").style.animationIterationCount=5;
document.getElementById("Sample").innerHTML="The animation Iteration count is now 5";
}
</script>
</head>
<body>
<p id="PARA1">Tellus elementum sagittis vitae et. Ac orci phasellus egestas tellus rutrum tellus pellentesque.</p>
<p>Click the below button to change how many times the above animation will run</p>
<button onclick="IncreaseIteration()">INCREASE COUNT</button>
<p id="Sample"></p>
</body>
</html> Đầu ra
Điều này sẽ tạo ra kết quả sau -
Khi nhấp vào nút PHỐI HỢP và nhấp vào Cho phép trên cửa sổ bật lên “Biết vị trí của bạn” -