transition:属性 过度时间 过度运动方式 延迟时间;
1、transition-property 设置过渡的属性,比如:width height background-color(所有属性写all. 分开属性用逗号隔开)
2、transition-duration 设置过渡的时间,比如:1s 500ms
3、transition-timing-function 设置过渡的运动方式
- linear 匀速
- ease 开始和结束慢速
- ease-in 开始是慢速
- ease-out 结束时慢速
- ease-in-out 开始和结束时慢速
- cubic-bezier(n,n,n,n)
- 比如:cubic-bezier(0.845, -0.375, 0.215, 1.335)
- 曲线设置网站:https://matthewlein.com/ceaser/
4、transition-delay 设置动画的延迟
5、transition: property duration timing-function delay 同时设置四个属性
<style type="text/css">
.box{
width:100px;
height:100px;
background-color:gold;
transition:width 300ms ease,height 300ms ease 300ms,background-color 300ms ease 600ms;
}
.box:hover{
width:300px;
height:300px;
background-color:red;
}
</style>
......
<div class="box"></div>
通过transition的值,控制hover属性发生的时间等属性
eg:最后一个div由曲线控制
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style type="text/css">
div{
width: 150px;
height: 50px;
background-color: gold;
margin-bottom: 20px;
}
div:nth-child(1){
transition: all 1s linear;
}
div:nth-child(2){
transition: all 1s ease;
}
div:nth-child(3){
transition: all 1s ease-in;
}
div:nth-child(4){
transition: all 1s ease-out;
}
div:nth-child(5){
transition: all 1s ease-in-out;
}
div:nth-child(6){
transition: all 1s cubic-bezier(0.750,-0.425,0.055,1.480);
}
div:hover{
width: 1000px;
}
</style>
</head>
<body>
<div>linear</div>
<div>ease</div>
<div>ease-in</div>
<div>ease-out</div>
<div>ease-in-out</div>
<div>bezier</div>
</body>
</html>