hooyantsing's Blog

P189_38_分分钟搞定3D立方体动画

字数统计: 271阅读时长: 1 min
2020/04/23

P189 38 分分钟搞定3D立方体动画

实战案例

效果:

e9f194e63bbd3e1858b0507b08bdd77e.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<!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: 200px;
            height: 200px;
            transform-style: preserve-3d;
            transform: perspective(900px) rotateX(-45deg);
            transition: 2s;
        }

        body:hover main {
            transform: perspective(900px) rotateX(180deg) rotateY(90deg);
        }

        div {
            width: 200px;
            height: 200px;
            position: absolute;
            transform-origin: center center 100px;
            display: flex;
            justify-content: center;
            align-items: center;
            font-size: 3em;
            color: white;
            opacity: .8;
        }

        div:nth-child(1) {
            transform: rotateY(90deg);
            background: #e74c3c;
        }

        div:nth-child(2) {
            transform: rotateY(180deg);
            background: #e67e22;
        }

        div:nth-child(3) {
            transform: rotateY(270deg);
            background: #27ae60;
        }

        div:nth-child(4) {
            transform: rotateY(360deg);
            background: #9b59b6;
        }

        div:nth-child(5) {
            transform-origin: bottom;
            transform: rotateX(-90deg);
            background: dodgerblue;
        }

        div:nth-child(6) {
            transform-origin: top;
            transform: rotateX(90deg);
            background: goldenrod;
        }
    </style>
</head>
<body>
<main>
    <div>1</div>
    <div>2</div>
    <div>3</div>
    <div>4</div>
    <div>5</div>
    <div>6</div>
</main>
</body>
</html>
CATALOG