HTML DOM 样式 animationPlayState 属性
htmlweb developmentfront end technology更新于 2024/5/20 15:40:17
animationPlayState 属性用于设置或获取动画状态,无论是正在运行还是暂停。这在切换动画时非常有用。
语法
以下是语法
设置 animationPlayState 属性 −
object.style.animationPlayState = "running|paused|initial|inherit"
值
以下是值 −
| Sr.No | 值 &说明 |
|---|---|
| 1 | Running 用于指定动画当前正在运行,是默认值。 |
| 2 | Paused 用于指定动画已暂停。 |
| 3 | Initial 用于将此属性设置为初始值。 |
| 4 | inherit 继承父级属性值。 |
示例
让我们看一个 animationPlayState 属性的示例 −
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 70px;
height: 30px;
border: 3px solid brown;
box-shadow: 0 20px 0 -3px orchid;
z-index:-1;
position: relative;
animation: move 5s infinite;
animation-play-state: play;
}
@keyframes move {
from {top: 0px; }
to {top: 400px;}
}
</style>
<script>
function stateToggle(){
document.getElementById("DIV1").style.animationPlayState="paused";
document.getElementById("Sample").innerHTML="The animation is now paused";
}
</script>
</head>
<body>
<div id="DIV1"></div>
<p>Click the below button to toggle the above animation state</p>
<button onclick="stateToggle()">CHANGE STATE</button>
<p id="Sample"></p>
</body>
</html>
输出
当框从上向下移动时,将产生以下输出 −

点击"更改状态" −

相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

