小码哥的IT人生

Style transitionDuration 属性 详解

css3基础 2023-07-30 03:30:02小码哥的IT人生shichen

Style transitionDuration 属性

定义和用法

transitionDuration 属性设置或返回过渡效果需要多少秒 (s) 或毫秒 (ms) 才能完成。

另请参阅:

CSS 参考手册:transition-duration 属性

实例

加速过渡效果:

document.getElementById("myDIV").style.transitionDuration = "1s";

 

完整实例【亲自试一试】:

<!DOCTYPE html>
<html>
<head>
<style>
#myDIV {
  border: 1px solid black;
  background-color: lightblue;
  width: 270px;
  height: 200px;
  overflow: auto;
  transition: all 5s;
}
#myDIV:hover {
  background-color: coral;
  width: 570px;
  height: 500px;
  padding: 100px;
  border-radius: 50px;
}
</style>
</head>
<body>
<p>请将鼠标悬停在 DIV 元素上,它的颜色和大小都会发生变化!</p>
<p>请点击“试一试”按钮,再次将鼠标悬停在 DIV 元素上。这些变化会发生得更快!</p>
<button onclick="myFunction()">试一试</button>
<div id="myDIV">
  <h1>myDIV</h1>
</div>
<script>
function myFunction() {
  document.getElementById("myDIV").style.transitionDuration = "1s";
}
</script>
</body>
</html>

可以使用本站在线JavaScript测试工具测试上述代码运行效果:http://www.phpcodeweb.com/runjs.html

语法

返回 transitionDuration 属性:

object.style.transitionDuration

设置 transitionDuration 属性:

object.style.transitionDuration = "time|initial|inherit"

属性值

描述
time 规定完成过渡效果需要多少秒或毫秒。默认值为 0,表示没有效果。
initial 将此属性设置为其默认值。请参阅 initial
inherit 从其父元素继承此属性。请参阅 inherit

技术细节

默认值: 0
返回值: 字符串,表示元素的 transition-duration 属性
CSS 版本: CSS3

浏览器支持

表中的数字注明了首个完全支持该属性的浏览器版本。

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
26.0 10.0 16.0 6.1 12.1

版权所有 © 小码哥的IT人生
Copyright © phpcodeweb All Rights Reserved
ICP备案号:苏ICP备17019232号-2  

苏公网安备 32030202000762号

© 2021-2024