CSS基础 (8)

过渡

transition过渡属性可以为一个元素在不同样式之间变化自动添加补间动画。

兼容性
过渡从IE10开始兼容,移动端兼容良好,过渡的动画更加细腻,内存开销小。

transition属性的基本使用

transition属性的四个要素:

	transition: width 1s linear 0s;

第一个要素:什么属性要过渡?
第二个要素:动画时长
第三个要素:变化速度的曲线
第四个要素:延迟时间

哪些属性可以设置过渡:
所有数值类型属性,都可以参与过渡,比如width,height,left,top,border-radius等。
背景颜色和文字颜色都可以被过渡。
所有变形(包括2D和3D)都可以被过渡。

如果要所有的属性参与过渡:
可以使用all

	transition: all 1s linear 0s;

all参数不可以乱用,会引发效率问题。

示例:

	* {
            margin: 0;
            padding: 0;
        }
        .box1{
            width: 200px;
            height: 200px;
            background-color: orange;
            transition: width 5s linear 0s;
            margin-bottom: 100px;
        }
        .box1:hover{
            width: 800px;
        }
        
        .box2 p {
            position: relative;
            width: 200px;
            height: 200px;
            left: 0;
            background-color: orange;
            transition: left 10s linear 0s;
            margin-bottom: 200px;
        }
        .box2:hover p {
            left: 1000px;
        }

        .box3 {
            width: 200px;
            height: 200px;
            background-color: red;
            transition: background-color 5s linear 0s;
            margin-bottom: 200px;
        }
        .box3:hover {
            background-color: orange;
        }
        .box4 {
            width: 200px;
            height: 200px;
            background-color: red;
            margin-bottom: 100px;
            border-radius: 0;
            transition: border-radius 5s linear 0s;
        }
        .box4:hover {
            border-radius: 50%;
        }

        .box5 {
            width: 200px;
            height: 200px;
            background-color: orange;
            margin-bottom: 10px;
            transition: transform 2s linear 0s;
        }
        .box5:hover {
            transform: scale(1.2) rotate(360deg);
        }

        .box6 {
            perspective: 300px;
            width: 200px;
            height: 200px;
            border: 1px solid #000;
        }
        .box6 p {
            width: 200px;
            height: 200px;
            background-color: orange;
            transition: transform 2s linear 0s;
        }
        .box6:hover p {
            transform: rotateX(360deg) rotateY(360deg);
        }

        .box7 {
            width: 200px;
            height: 200px;
            background-color: orange;
            border-radius: 0%;
            transition: all 2s linear 0s;
        }
        .box7:hover {
            width: 400px;
            height: 150px;
            background-color: rgb(0, 255, 0);
            border-radius: 50%;
        }

过渡的四个小属性

属性意义
transition-property哪些属性要过渡
transition-duration动画时间
transition-timing-function动画变化曲线(缓动效果)
transition-delay延迟时间

过渡的缓动效果

缓动参数
transition属性的第三个参数是缓动参数,也是变化速度曲线。

常用的缓动参数
在这里插入图片描述

示例:

	.box8 {
            border: 1px solid #000;
        }
        .box8 p {
            width: 60px;
            height: 60px;
            background-color: orange;
            position: relative;
            left: 0;
            margin-bottom: 10px;
            transition: left 3s linear 0s;
        }
        .box8 p:nth-child(1){
            transition-timing-function: linear;
        }
        .box8 p:nth-child(2){
            transition-timing-function: ease;
        }
        .box8 p:nth-child(3){
            transition-timing-function: ease-in;
        }
        .box8 p:nth-child(4){
            transition-timing-function: ease-in-out;
        }
        .box8 p:nth-child(5){
            transition-timing-function: ease-out;
        }
        
        .box8:hover p {
            left: 1800px;
        }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值