HTML - DOM樣式物件 animationName 屬性



HTML DOM 樣式物件 **animationName** 屬性用於獲取或設定 @keyframes 動畫的動畫名稱。

語法

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

設定 animationName 屬性
object.style.animationName= "none | keyframename | initial | inherit";
獲取 animationName 屬性
object.style.animationName;

屬性值

描述
none 這是預設值,表示沒有動畫。
keyframename 指定要繫結到選擇器的關鍵幀的名稱。
initial 用於將此屬性設定為其預設值。
inherit 用於繼承其父元素的屬性。

返回值

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

HTML DOM 樣式物件“animationName”屬性示例

以下示例根據 animationName 屬性更改動畫。

<!DOCTYPE html>
<html lang="en">
<head>
    <title>
        HTML DOM Style Object animationName Property
    </title>
    <style>
        #animation {
            width: 100px;
            height: 100px;
            background: #04af2f;
            position: relative;
            animation: right 3s infinite;
        }
        @keyframes right {
            from {
                left: 0px;
            }
            to {
                left: 400px;
            }
        }
        @keyframes down {
            from {
                top: 0px;
                width: 100px;
                height: 100px;
            }
            to {
                top: 400px;
                width: 200px;
                height: 200px;
                background: yellow
            }
        }
    </style>
</head>
<body>
    <p>Click below to change the animation.</p>
    <button onclick="fun()">Click me</button>
    <div id="animation"></div>
    <script>
        function fun() {
            document.getElementById("animation").style.animationName = "down";
        }
    </script>
</body>
</html>

支援的瀏覽器

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