hooyantsing's Blog

P212_4_移动的小方块

字数统计: 160阅读时长: 1 min
2020/04/24

P212 4 移动的小方块

实战案例

介绍:对帧动画(@keyframes)的简单应用。

效果:

409537bffcec71179fbb3eebb890a59f.png

源码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        body {
            height: 100vh;
            width: 100vw;
            display: flex;
            justify-content: center;
            align-items: center;
            background: #2c3e50;
        }

        main {
            width: 400px;
            height: 400px;
            border: solid 2px white;
        }

        div {
            width: 100px;
            height: 100px;
            background: #e67e22;
            animation-name: hd;
            animation-duration: 2s;
        }

        @keyframes hd {
            25% {
                transform: translateX(300px);
            }
            50% {
                transform: translate(300px, 300px);
            }
            75% {
                transform: translateY(300px);
            }
        }
    </style>
</head>
<body>
<main>
    <div></div>
</main>
</body>
</html>
CATALOG