HTML DOM 样式 animationName 属性

htmlweb developmentfront end technology更新于 2024/5/20 16:12:17

animationName 属性用于获取或设置 @keyframes 引用的动画名称。

语法

以下是语法 −

设置 animationName 属性 −

object.style.animationName = "none|keyframename|initial|inherit"

值

以下是值 −

Sr.No值 &说明
1None
这是默认值,表示没有动画。
2keyframename
指定要将选择器绑定到的关键帧名称。
3initial
用于将此属性设置为初始值。
4inherit
继承父级属性值。

示例

让我们看一下 animationName 属性的示例 −

<!DOCTYPE html>
<html>
<head>
<style>
   div {
      width: 60px;
      height: 40px;
      border: 10px groove fuchsia;
      position: relative;
      animation-name: bravo;
      animation-iteration-count:infinite;
      animation-duration: 5s;
   }
   @keyframes bravo {
      from {left: 0px; }
      to {left: 600px;}
   }
   @keyframes NEW_FRAME {
      from {left:550px; }
      to {left: 0px;}
   }
</style>
<script>
   function nameChange(){
      document.getElementById("DIV1").style.animationName="NEW_FRAME";
      document.getElementById("Sample").innerHTML="The animation name is now NEW_FRAME";
   }
</script>
</head>
<body>
<div id="DIV1">SAMPLE TEXT</div>
<p>Click the below button to change the above animation fillmode property</p>
<button onclick="nameChange()">CHANGE NAME</button>
<p id="Sample"></p>
</body>
</html>

输出

这将产生以下输出。动画从左向右移动 −

点击"更改名称"按钮后,动画从左向右移动 −


相关文章


有用资源