HTML5前端开发入门之CSS过渡模块

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>54-过渡模块</title>
    <style>
        div{
            width: 100px;
            height: 100px;
            background-color: red;
            /*告诉系统哪个属性需要执行过渡效果*/
            /*transition-property: width,background-color;*/
            /*transition-duration: 5s,5s;*/
            /*告诉系统延迟多少秒之后才开始过渡动画*/
            /*transition-delay: 2s;*/
            /*简写*/
            /*transition: width 5s linear 2s,background-color 5s linear 2s;*/
            transition: all 5s 2s;
        }

        /*:hover 这个伪类选择器除了可以用在a标签上,还可以用在其他任何标签*/
        div:hover{
            width: 300px;
            background-color: yellow;
        }
        ul{
            width: 800px;
            height: 500px;
            margin: 0 auto;
            padding: 0;
            background-color: pink;
            border: 1px solid #000;
        }
        ul li{
            list-style: none;
            width: 100px;
            height: 50px;
            margin-top: 50px;
            margin-left: 0;
            background-color: yellow;
            transition-property: margin-left;
            transition-duration: 10s;
        }
        ul:hover li{
            margin-left: 700px;
        }
        /*改变过渡效果的速度形式,匀速/先快后慢/先慢后快等等*/
        ul li:nth-child(1){
            transition-timing-function: linear;
        }
        ul li:nth-child(2){
            transition-timing-function: ease;
        }
        ul li:nth-child(3){
            transition-timing-function: ease-in;
        }
        ul li:nth-child(4){
            transition-timing-function: ease-out;
        }
        ul li:nth-child(5){
            transition-timing-function: ease-in-out;
        }
    </style>
</head>
<body>
<!--
1.过渡三要素
1.1必须要有属性发生变化
1.2必须告诉系统哪个属性需要执行过渡效果
1.3必须告诉系统过渡效果持续的时长

2.注意点:
当多个属性需要同时执行过渡效果时用逗号隔开即可
transition-property: width,background-color;
transition-duration: 5s,5s;

3.过渡连写格式:
transition: 过渡属性 过渡时长 运动速度 延迟时间;

注意点:
1.和分开写一样,如果想给多个属性添加效果也是用逗号隔开
2.连写的时候,可以省略后面的两个参数,因为只要编写了前面两个参数
 就已经满足了过渡的三要素
3.如果多个属性运动的速度/延迟的时间/持续时间都一样,可以简写为:
transition:all 5s;

4.编写过渡的套路:
4.1不要管过渡,先编写界面
4.2修改我们认为需要修改的属性
4.3再回过头去给被修改属性的那个元素添加过渡即可
-->
<div></div>
<ul>
    <li>linear</li>
    <li>ease</li>
    <li>ease-in</li>
    <li>ease-out</li>
    <li>ease-in-out</li>
</ul>
</body>
</html>

猜你喜欢

转载自blog.csdn.net/qq_41886761/article/details/85625987