小码哥的IT人生

Style transitionTimingFunction 属性 详解

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

Style transitionTimingFunction 属性

定义和用法

transitionTimingFunction 属性规定了过渡效果的速度曲线。

此属性允许过渡效果在其持续时间内改变速度。

另请参阅:

CSS 参考手册:transition-timing-function 属性

实例

改变过渡效果的速度曲线:

document.getElementById("myDIV").style.transitionTimingFunction = "linear";

 

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

<!DOCTYPE html>
<html>
<head>
<style>
#myDIV {
  border: 1px solid black;
  background-color: lightblue;
  width: 270px;
  height: 200px;
  overflow: auto;
  transition: all 2s;
}
#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.transitionTimingFunction = "linear";
}
</script>
</body>
</html>

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

语法

返回 transitionTimingFunction 属性:

object.style.transitionTimingFunction

设置 transitionTimingFunction 属性:

object.style.transitionTimingFunction =
"ease|linear|ease-in|ease-out|ease-in-out|cubic-bezier()|initial|inherit"

属性值

描述
ease

默认值。规定缓慢开始,然后快速,再然后缓慢结束的过渡效果。

相当于:cubic-bezier(0.25, 0.1, 0.25, 1) 。

linear

规定从开始到结束速度相同的过渡效果。

相当于:cubic-bezier(0, 0, 1, 1) 。

ease-in

规定缓慢启动的过渡效果。

相当于:cubic-bezier(0.42, 0, 1, 1) 。

ease-out

规定缓慢结束的过渡效果。

相当于:cubic-bezier(0, 0, 0.58, 1) 。

ease-in-out

规定缓慢开始和结束的过渡效果。

相当于:cubic-bezier(0.42, 0, 0.58, 1) 。

cubic-bezier(n, n, n, n)

在三次贝塞尔函数中定义您自己的值。

可能的值是从 0 到 1 的数值。

initial 将此属性设置为其默认值。请参阅 initial
inherit 从其父元素继承此属性。请参阅 inherit

技术细节

默认值: ease
返回值: 字符串,表示元素的 transition-timing-function 属性
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