遨翔在知識的海洋裡----css3(一)

遨翔在知識的海洋裡發表於2018-03-22

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>
複製程式碼

相關文章