-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3d-cube.html
More file actions
88 lines (79 loc) · 2.19 KB
/
Copy path3d-cube.html
File metadata and controls
88 lines (79 loc) · 2.19 KB
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
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>3D 旋转立方体</title>
<style>
body {
margin: 0;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background-color: #1a1a24;
font-family: sans-serif;
}
.scene {
width: 200px;
height: 200px;
perspective: 600px; /* 开启3D视角 */
}
.cube {
width: 100%;
height: 100%;
position: relative;
transform-style: preserve-3d;
transform: translateZ(-100px);
animation: rotate 10s infinite linear;
}
.cube__face {
position: absolute;
width: 200px;
height: 200px;
border: 2px solid #fff;
line-height: 200px;
font-size: 40px;
font-weight: bold;
color: white;
text-align: center;
background: rgba(0, 210, 255, 0.4);
box-shadow: 0 0 20px rgba(0, 210, 255, 0.6);
}
/* 立方体的六个面 */
.cube__face--front { transform: rotateY( 0deg) translateZ(100px); }
.cube__face--right { transform: rotateY( 90deg) translateZ(100px); }
.cube__face--back { transform: rotateY(180deg) translateZ(100px); }
.cube__face--left { transform: rotateY(-90deg) translateZ(100px); }
.cube__face--top { transform: rotateX( 90deg) translateZ(100px); }
.cube__face--bottom { transform: rotateX(-90deg) translateZ(100px); }
/* 旋转动画 */
@keyframes rotate {
0% { transform: translateZ(-100px) rotateX(0deg) rotateY(0deg); }
100% { transform: translateZ(-100px) rotateX(360deg) rotateY(360deg); }
}
.controls {
position: absolute;
bottom: 50px;
color: #aaa;
text-align: center;
width: 100%;
}
</style>
</head>
<body>
<div class="scene">
<div class="cube">
<div class="cube__face cube__face--front">前</div>
<div class="cube__face cube__face--back">后</div>
<div class="cube__face cube__face--right">右</div>
<div class="cube__face cube__face--left">左</div>
<div class="cube__face cube__face--top">上</div>
<div class="cube__face cube__face--bottom">下</div>
</div>
</div>
<div class="controls">
<p>纯 CSS 实现的 3D 旋转立方体效果</p>
</div>
</body>
</html>