遨翔在知识的海洋里----css3(一)

237 阅读1分钟

css3--animation(动画)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        .div1{
            position: relative;
            width: 100px;
            height: 100px;
            background-color: #ff0000;
            animation: appMove 8s infinite;  //appMove为声明一个动画变量,8s为0-100%的动画持续时间,infinite为是否循环播放动画
            animation-direction:alternate; //是否逆向播放动画0-100 再100-0,才是跑完一个动画流程
        }
        @keyframes appMove{
        //from to 为0-100的简写
            /* from{
                left: 0;
                background-color: #ff0000;
            }
            to{
                left: 100px;
                background-color: #00aaee;
            } */
            0%{
                left: 0px;
                top: 0px;
                background-color: #ff0000;
            }
            25%{
                left: 100px;
                top: 0px;
                background-color: #00aaee;
            }
            50%{
                left: 100px;
                top: 100px;
                background-color: green;
            }
            75%{
                left: 0px;
                top: 100px;
                background-color: yellow;
            }
            100%{
                left: 0px;
                top: 0px;
                background-color: #ff0000;
            }
        }
    </style>
</head>
<body>
    <div class="div1">
        div1
    </div>
</body>
</html>