动画(1)

奔跑的少年的启示

<!DOCTYPE html>
<html lang="zh">
    <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>
            .box1{
                width:256px;
                height:256px;
                margin:0px auto;
                background-image: url("../img/12/bg2.png");
                animation:running-man 0.5s steps(5) infinite;
            }
            
            @keyframes running-man {
                from{
                    background-position: 0px 0px;
                }

                to{
                    background-position: -1280px 0px;
                }
            }
        </style>
    </head>
    <body>
        <div class="box1"></div>
    </body>
</html>

在这里插入图片描述

注意上面一种设置方法

在这里插入图片描述

下面这种方法是利用,不给背景图片设置background-repeat:no-repeat;时的特点

<!DOCTYPE html>
<html lang="zh">
    <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>
            .box1{
                width:256px;
                height:256px;
                margin:0px auto;
                background-image: url("../img/12/bg2.png");
                animation:running-man 0.5s steps(6) infinite;
            }
            
            @keyframes running-man {
                from{
                    background-position: 0px 0px;
                }

                to{
                    background-position: -1536px 0px;
                }
            }
        </style>
    </head>
    <body>
        <div class="box1"></div>
    </body>
</html>

在这里插入图片描述
在这里插入图片描述

上面第二种方法,之所以直接将to中的background-position的第一个参数设置为整张图片的大小,就在于,我没有在.box1中写background-repeat:no-repeat,并且让每一帧图片的宽度等于.box1的宽度,所以,造成了,我们实际看不见的背景图片的平铺,进一步,我们就可以不用计算,直接用整张图片来进行处理

跳球动画

<!DOCTYPE html>
<html lang="zh">
    <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>
            .box1{
                width:800px;
                height:800px;
                border-bottom:10px black solid;
                margin:0px auto;
                overflow:hidden;
            }

            .box2, .box3, .box4, .box5, .box6, .box7, .box8, .box9{
                width:100px;
                height:100px;
                border-radius:50px;
                background-color:#bfa;
                animation:test 10s ease-in forwards;
                float:left;
            }

            .box{
                width:100px;
                height:100px;
                border-radius:50px;
                background-color:#bfa;
                animation:test 10s ease-in forwards infinite;
                float:left;
            }

            .box2{
                background-color:red;
                animation-delay:0.5s;
            }

            .box3{
                background-coloro:orange;
                animation-delay:1s;
            }

            .box4{
                background-color:yellow;
                animation-delay:1.5s;
            }

            .box5{
                background-color:green;
                animation-delay:2s;
            }

            .box6{
                background-color:cyan;
                animation-delay:2.5s;
            }

            .box7{
                background-color:blue;
                animation-delay:3s;
            }
            
            .box8{
                background-color:purple;
                animation-delay:3.5s;
            }

            .box9{
                background-color:pink;
                animation-delay:4s;
            }



            @keyframes test{
                0%{
                    margin-top:0px;
                }

                20%{
                    margin-top:700px;
                }

                40%{
                    margin-top:100px;
                }
                60%{
                    margin-top:700px;
                }
                80%{
                    margin-top:300px;
                }
                100%{
                    margin-top:700px;
                }
            }
        </style>
    </head>
    <body>
        <div class="box1">
            <div class="box2 box">2</div>
            <div class="box3 box">3</div>
            <div class="box4 box">4</div>
            <div class="box5 box">5</div>
            <div class="box6 box">6</div>
            <div class="box7 box">7</div>
            <div class="box8 box">8</div>
            <div class="box9 box">9</div>
        </div>
    </body>
</html>

在这里插入图片描述

在这里插入图片描述

对于关键帧,可以利用百分号去定详细的阶段

animation只能写一次,写两次,会出现样式重置的问题,此外,可以通过具体的animation-XX去对应到修改样式

鸭子表的启示:制作表的指针时,其实不是那个指针在转,而是那个那个指针的外部容器再转(这个思想和让父元素浮动,虽然该父元素的子元素没有浮动,但是由于该子元素在父元素内,所以当父元素在动的时候,其子元素的位置也发生了变化)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值