HTML - DOM Style 物件 animationIterationCount 屬性



HTML DOM Style 物件的 **animationIterationCount** 屬性用於設定或返回動畫應播放的次數。

語法

以下是獲取或設定 animationIterationCount 屬性的語法。

設定 animationIterationCount 屬性
object.style.animationIterationCount= "number | infinite | initial | inherit";
獲取 animationIterationCount 屬性
object.style.animationIterationCount;

屬性值

描述
數字 它指定動畫將播放或重複的次數。預設值為 1。
無限 它指定動畫將無限次播放。
初始 它用於將此屬性設定為其預設值。
繼承 它用於繼承其父元素的屬性。

返回值

它返回一個字串值,表示元素的 animation-iteration-count 屬性。

HTML DOM Style 物件“animationIterationCount”屬性示例

在以下示例中,我們單擊數字時將迭代次數設定為 5,並單擊“無限”以進行無限次重複。

<!DOCTYPE html>
<html lang="en">
<head>
    <title>
        HTML DOM Style Object animationIterationCount Property
    </title>
    <style>
        #animation {
            width: 100px;
            height: 100px;
            background: #04af2f;
            position: relative;
            animation: right 3s;
        }
        @keyframes right {
            from {
                left: 0px;
            }
            to {
                left: 400px;
            }
        }
    </style>
</head>
<body>
    <p>
        Click on 'number' to repeat animation 
        for 5 times and chose 'infinite' for
        infinite repetitions.
    </p>
    <button onclick="number()">Number</button>
    <button onclick="infinite()">Infinite</button>
    <div id="animation"></div>
    <script>
        function number() {
            document.getElementById("animation").style
                .animationIterationCount = "5";
        }
        function infinite() {
            document.getElementById("animation").style
                .animationIterationCount = "infinite";
        }
    </script>
</body>
</html>

支援的瀏覽器

屬性 Chrome Edge Firefox Safari Opera
animationIterationCount 是 43 是 12 是 16 是 9 是 30
html_dom_style_object_reference.htm
廣告