-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
172 lines (141 loc) · 3.34 KB
/
index.html
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>神奇的魔方</title>
<style type="text/css">
* {
margin: 0px;
padding: 0px;
}
.container {
width: 300px;
height: 300px;
/*border: 1px solid #000;*/
margin: 150px auto;
perspective: 20000px;
}
.box {
width: 300px;
height: 300px;
/*控制子元素保持3D转换*/
transform-style: preserve-3d;
/*测试代码*/
/*transform: rotateX(45deg) rotateY(45deg);*/
animation: ro 4s linear infinite;
}
@keyframes ro {
0% {
transform: rotateX(0deg) rotateY(0deg);
}
100% {
transform: rotateX(360deg) rotateY(360deg);
}
}
.box-page {
width: 300px;
height: 300px;
/*位置初始化*/
position: absolute;
transform-style: preserve-3d;
}
.top {
/*background-color: green;*/
transform: translateZ(150px);
}
.bottom {
/*background-color: green;*/
transform: translateZ(-150px) rotateX(180deg);
}
.left {
/*background-color: orange;*/
transform: translateX(-150px) rotateY(-90deg);
}
.right {
/*background-color: pink;*/
transform: translateX(150px) rotateY(90deg);
}
.before {
/*background-color: blue;*/
transform: translateY(150px) rotateX(-90deg);
}
.after {
/*background-color:yellow;*/
transform: translateY(-150px) rotateX(90deg);
}
.box-page div:nth-child(1) {
animation: a1 4.5s ease-in;
}
.box-page div:nth-child(2) {
animation: a1 4.5s ease-in 0.5s;
}
.box-page div:nth-child(3) {
animation: a1 4.5s ease-in 1s;
}
.box-page div:nth-child(4) {
animation: a1 4.5s ease-in 1.5s;
}
.box-page div:nth-child(5) {
animation: a1 4.5s ease-in 2s;
}
.box-page div:nth-child(6) {
animation: a1 4.5s ease-in 2.5s;
}
.box-page div:nth-child(7) {
animation: a1 4.5s ease-in 3s;
}
.box-page div:nth-child(8) {
animation: a1 4.5s ease-in 3.5s;
}
.box-page div:nth-child(9) {
animation: a1 4.5s ease-in 4s;
}
@keyframes a1 {
0% {
transform: translateZ(0px) scale(1) rotateZ(0deg);
}
20% {
transform: translateZ(300px) scale(0) rotateZ(720deg);
}
90% {
transform: translateZ(300px) scale(0) rotateZ(720deg);
}
100% {
transform: translateZ(0px) scale(1) rotateZ(0deg);
}
}
</style>
</head>
<body>
<div class="container">
<div class="box">
<div class="box-page top"></div>
<div class="box-page bottom"></div>
<div class="box-page left"></div>
<div class="box-page right"></div>
<div class="box-page before"></div>
<div class="box-page after"></div>
</div>
</div>
<script type="text/javascript">
var arr = document.querySelectorAll(".box-page");
//遍历6个面中的每个面
for (var n = 0; n < arr.length; n++) {
//外层循环行
for (var r = 0; r < 3; r++) {
//内层循环遍历
for (var c = 0; c < 3; c++) {
//创建元素
var divs = document.createElement("div");
divs.style.cssText = "width:100px;height:100px;border:2px solid #fff;box-sizing:border-box;position:absolute;background-image:url(images/a" + n + ".jpg);background-size:300px 300px;";
arr[n].appendChild(divs);
divs.style.left = c * 100 + "px";
divs.style.top = r * 100 + "px";
divs.style.backgroundPositionX = -c * 100 + "px";
divs.style.backgroundPositionY = -r * 100 + "px";
}
}
}
</script>
</body>
</html>