CSS3--CSS3过渡

CSS3过渡

过渡(transition)

  • 允许CSS的值在一定时间区间内平滑地过渡
  • 在鼠标单击、获得焦点、被点击或对元素任何改变中触发,并圆滑地以动画效果改变CSS的属性值

兼容性

| IE10+ | Firefox16+ | Chrome26+ | Safari6.1+ | Opera12.1+ |

transition-property

检索或设置对象中的参与过渡的属性

语法

transition-property: none | all | property;

  • none : 没有属性改变
  • all : 所有属性改变(默认)
  • property : 元素属性名
1
2
3
4
5
6
7
.box{
-webkit-transition-property: transform;
-moz-transition-property: transform;
-ms-transition-property: transform;
-o-transition-property: transform;
transition-property: transform;
}

transition-duration

检索或设置对象中的参与过渡的持续时间

语法

transition-duration: time;

  • time : 规定完成过渡效果需要花费的时间(以秒或毫秒计),默认是0
1
2
3
4
5
6
7
.box{
-webkit-transition-duration: 2s;
-moz-transition-duration: 2s;
-ms-transition-duration: 2s;
-o-transition-duration: 2s;
transition-duration: 2s;
}

transition-timing-function

检索或设置对象中的参与过渡的动画类型

语法

transition-timing-function: ease | linear | ease-in | ease-out | ease-in-out | cubic-bezier(n,n,n,n)

  • 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) : 在 cubic-bezier 函数中定义自己的值。可能的值是 0 至 1 之间的数值
1
2
3
4
5
6
7
.box{
-webkit-transition-timing-fuction: ease-in;
-moz-transition-timing-fuction: ease-in;
-ms-transition-timing-fuction: ease-in;
-o-transition-timing-fuction: ease-in;
transition-timing-fuction: ease-in;
}

transition-delay

检索或设置对象延迟过渡的时间

语法

transition-delay: time

  • time : 规定延迟过渡效果的时间(以秒或毫秒计),默认是0
1
2
3
4
5
6
7
.box{
-webkit-transition-duration: 2s;
-moz-transition-duration: 2s;
-ms-transition-duration: 2s;
-o-transition-duration: 2s;
transition-duration: 2s;
}

transition属性简写

语法

transition: property duration timing-fuction delay

1
2
3
4
5
6
7
.box{
-webkit-transition: transform 2s ease-in-out 1s;
-moz-transition: transform 2s ease-in-out 1s;
-ms-transition: transform 2s ease-in-out 1s;
-o-transition: transform 2s ease-in-out 1s;
transition: transform 2s ease-in-out 1s;
}
文章目录
  1. 1. CSS3过渡
    1. 1.1. 过渡(transition)
    2. 1.2. transition-property
    3. 1.3. transition-duration
    4. 1.4. transition-timing-function
    5. 1.5. transition-delay
    6. 1.6. transition属性简写
|