HTML DOM 样式 animationDuration 属性
htmlweb developmentfront end technology更新于 2024/5/20 18:20:17
animationDuration 属性用于指定动画完成一个周期所需的时间长度。
语法
以下是语法 −
设置 animationDuration 属性 −
object.style.animationDuration = "time|initial|inherit"
值
以下是值 −
| 值 | 描述 |
|---|---|
| Time | 用于指定动画开始前等待的时间(以秒或毫秒为单位)。时间的默认值为 0。 |
| initial | 用于将此属性设置为初始值。 |
| inherit | 用于继承父级属性值 |
示例
让我们看一个 animationDuration 属性的示例 −
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 25px;
height: 25px;
border-radius: 50%;
border: 8px solid orange;
position: relative;
animation: ring infinite;
animation-duration: 5s;
}
@keyframes ring {
from {top: 0px; left:0px}
to {border-color: purple; left: 500px;}
}
</style>
<script>
function changeDuration(){
document.getElementById("DIV1").style.animationDuration="10s";
document.getElementById("Sample").innerHTML="The animation duration has been increased from 5s to 10s";
}
</script>
</head>
<body>
<div id="DIV1"></div>
<p>Click the below button to create the above animation duration</p>
<button onclick="changeDuration()">CHANGE DURATION</button>
<p id="Sample"></p>
</body>
</html>
输出
这将产生以下输出 −

动画会在一段时间后改变颜色 −

点击"更改时长"按钮后,动画时长将增加至 10 秒 −

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

