css

46、过渡

yu
yu
2024-09-30 / 0 评论 / 9 阅读 / 正在检测是否收录...

1、基本使用


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>过渡基本使用</title>
    <style>
        .box1{
            width: 200px;
            height: 200px;
            background-color: orange;
            opacity: 0.5;
            /* 设置哪个属性需要过渡效果 */
            transition-property: height,width;
            /* 让所有能过渡的属性过渡 */
            /* 设置过渡的时间 */
            /* 分别设置 */
            /* transition-duration: 1s,5s; */
            /* 一个 */
            transition-duration: 1s;
        }
        .box1:hover{
            height: 400px;
            width: 400px;
            background-color: green;
            transform: rotate(45deg);
            box-shadow: 0px 0px 20px black;
            opacity: 1;
        }
    </style>
</head>
<body>
    <div class="box1"></div>
</body>
</html>

2、高级使用


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>过渡高级使用</title>
    <style>
        .outer{
            width: 1300px;
            height: 900px;
            border: 1px solid black;
        }
        .outer:hover .box{
            width: 1300px;
        }
        .box{
            width: 200px;
            height: 100px;
            /* 让所有能过渡的属性,都过渡 */
            /* 设置哪个属性需要过渡效果 */
           transition-duration: all;
            /* 设置一个时间,所有人都用 */
            /* 一个 */
            transition-duration: 5s;
            /* 过渡延迟 */
            /* transition-delay: 2s; */

        }
        .box1 {
            background-color: skyblue;
            /*平滑过渡 
            transition-timing-function: ease; */

        }
        .box2 {
            background-color: orange;
            transition-timing-function: linear;
        }
        .box3 {
            background-color: gray;
            transition-timing-function: ease-in;
        }
        .box4 {
            background-color: tomato;
            transition-timing-function: ease-out;
        }
        .box5 {
            background-color: green;
            transition-timing-function: ease-in-out;
        }
        .box6 {
            background-color: purple;
            transition-timing-function: step-start;
        }
        .box7 {
            background-color: chocolate;
            transition-timing-function: step-end;
        }
        .box8 {
            background-color: skyblue;
            transition-timing-function: steps(20,end);
        }
        .box9 {
            background-color: black;
            transition-timing-function: cubic-bezier(.88,1.03,.78,1.24);
            color: white;
        }
        
    </style>
</head>
<body>
    <div class="outer">
    <div class="box box1">ease(慢,块,慢)</div>
    <div class="box box2">linear(匀速)</div>
    <div class="box box3">ease-in(先慢后快)</div>
    <div class="box box4">ease-out(块,慢)</div>
    <div class="box box5">ease-in-out(慢,块,慢)</div>
    <div class="box box6">step-start(不考虑过渡时间,直接终点)</div>
    <div class="box box7">step-end(考虑过渡时间,无过渡效果,过渡时间到了以后,瞬间到达)</div>
    <div class="box box8">steps()(分布过渡)end慢一下,start快一下</div>
    <div class="box box9">cubic-bezier.com贝塞尔曲线</div>
    </div>
</body>
</html>

3、过渡的复合属性


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>复合属性</title>
    <style>
        .outer{
            width: 1000px;
            height: 100px;
            border: 1px solid black;
        }
        .inner{
            width: 100px;
            height: 100px;
            background-color: orange;
            transition: 3s all linear;
        }
        .outer:hover .inner{
            width: 1000px;
        }
    </style>
</head>
<body>
    <div class="outer">
        <div class="inner"></div>
    </div>
</body>
</html>

4、案列


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .outer{
            width: 400px;
            height: 225px;
            position: relative;
            overflow: hidden;
        }
        .mask{
            width: 400px;
            height: 225px;
            background-color: black;
            color: white;
            position: absolute;
            top: 0;
            left: 0;
            text-align: center;
            line-height: 225px;
            font-size: 100px;
            opacity: 0;
            transition: 1s linear all;
                    
        }
        .outer:hover .mask{
            opacity: 0.5;

        }
        .outer:hover img{
            transform: scale(1.6) rotate(20deg);
        }
        img{
            transition: 0.5s linear;
        }
    </style>
</head>
<body>
    <div class="outer">
        <img src="./tp/djsy2.jpg" alt="">
        <div class="mask">桐人</div>
    </div>
</body>
</html>
0

评论 (0)

取消