-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
239 lines (208 loc) · 8.44 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
<!DOCTYPE html>
<html>
<head>
<title>元旦快乐</title>
<meta charset="UTF-8">
<meta name="Author" content="只会切图的前端">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
</head>
<body>
<div id="container"></div>
<audio autoplay loop controls id="music">
<source src="img/875007460.mp3">
</audio>
<script src="js/three.min.js"></script>
<!-- 补间动画 -->
<script src="js/tween.min.js"></script>
<!-- 轨迹球控制器(TrackballControls) -->
<script src="js/TrackballControls.js"></script>
<script src="js/CSS3DRenderer.js"></script>
<script>
let musicDom = document.getElementById("music");
let picArr = [];
let arr = [
'/bmltYV8yNzk5NTAxMTYwMTdfMTczNTU0MjM0NDcxMV84YTQ2NjVmNS1iMjJkLTRiNzktOWYwNS0xMjRkZjk0OGYxNGY=',
'/bmltYV8yNzk5NTAxMTYwMTdfMTczNTU0MjQ1NzIwOF85OWI3YTNiNi1lYWYwLTRkM2EtYjY2Mi1mM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NDQzNjNiOS01Yjc4LTQ2NjAtYjk5Zi0wOWU5OTQ2M2UzMDQ=',
'/bmltYV8yNzk5NTAxMTYwMTdfMTczNTU0MzMwOTYwNF9mMGU3NzM5NC1lNDdiLTQwNGQtODYyNC03Mjg3YjdjNDFjMjU=',
'/bmltYV8yNzk5NTAxMTYwMTdfMTczNTU0MzMzMjIwNF8zNzc4ZmRlOC0zNDk4LTQxNzYtYWI2OC03ZWE5NDM2ZjkxMzE=',
'/bmltYV8yNzk5NTAxMTYwMTdfMTczNTU0MzM1NTc5OF8xZGE3ZjE0NS1kOGY1LTRhZjktOTJjNS04Y2Q3MDU0MzNiMDc=',
'/bmltYV8yNzk5NTAxMTYwMTdfMTczNTU0MzM3NzMzM19jZjYyZmQ5Mi1kZGFjLTQ4MTgtYWM5YS05OTQ3ZDI5NTk3Yzc=',
'/bmltYV8yNzk5NTAxMTYwMTdfMTczNTU0MzM5Nzg2M18zMjEyNjc4NS04M2Q0LTRmMDgtOGY2OC04ZGYwODc3NTk3MjY=',
'/bmltYV8yNzk5NTAxMTYwMTdfMTczNTU0MzQzMjgxOF9mOGFjNzBmZi03NGJkLTQ3NGEtOGNmYS1lNGI5NGMwMTc3NWY=',
'/bmltYV8yNzk5NTAxMTYwMTdfMTczNTU0MzQ1NjEwMV81YjMxNjFlOS1mOTA0LTQwZTgtYWQzMC02NjU1MGI0MDVhNzc=',
'/bmltYV8yNzk5NTAxMTYwMTdfMTczNTU0MzQ3MzczMV9lNjcyMWU3YS0wNTAxLTQ3YWItOWMwYS02NGU4MjIwODQxYzg='
]
// 生成随机图片
for (let i = 0; i < 199; i++) {
let yu = i % 32;
if (yu == 0) {
yu = 32;
}
picArr.push({
url: "https://nim-nosdn.netease.im/MjYxNjk1NDU="+arr[yu]
});
}
let table = [];
for (let i = 0; i < picArr.length; i++) {
table[i] = {};
if (i < picArr.length) {
table[i] = picArr[i];
}
table[i].p_x = i % 20 + 1;
table[i].p_y = Math.floor(i / 20) + 1;
}
//场景(scene)、相机(camera)和渲染器(renderer),这样我们就能透过摄像机渲染出场景
let camera, scene, renderer;
let controls;
let objects = [];
let targets = [];
init();
animate();
function init() {
//透视相机
camera = new THREE.PerspectiveCamera(40, window.innerWidth / window.innerHeight, 1, 10000);
camera.position.z = 3000;
//创建一个新的场景对象。
scene = new THREE.Scene();
for (let i = 0; i < table.length; i++) {
//创建dom元素
let dom = document.createElement('div');
dom.className = 'element';
let img = document.createElement('img');
img.src = table[i].url;
dom.appendChild(img);
let object = new THREE.CSS3DObject(dom);
object.position.x = Math.random() * 4000 - 2000;
object.position.y = Math.random() * 4000 - 2000;
object.position.z = Math.random() * 4000 - 2000;
scene.add(object);
objects.push(object);
}
//三维向量
let vector = new THREE.Vector3();
//球坐标
let spherical = new THREE.Spherical();
for (let i = 0, l = objects.length; i < l; i++) {
let phi = Math.acos(-1 + (2 * i) / l);
let theta = Math.sqrt(l * Math.PI) * phi;
//这是Three.js中大部分对象的基类,提供了一系列的属性和方法来对三维空间中的物体进行操纵。
let object = new THREE.Object3D();
spherical.set(800, phi, theta);
object.position.setFromSpherical(spherical);
vector.copy(object.position).multiplyScalar(2);
object.lookAt(vector);
targets.push(object);
}
//CSS3DRenderer用于通过CSS3的transform属性, 将层级的3D变换应用到DOM元素上
renderer = new THREE.CSS3DRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.domElement.style.position = 'absolute';
document.getElementById('container').appendChild(renderer.domElement);
// 鼠标控制
controls = new THREE.TrackballControls(camera, renderer.domElement);
controls.rotateSpeed = 0.5;//旋转的速度
controls.minDistance = 500;//够将相机向内移动多少
controls.maxDistance = 6000;//将相机向外移动多少
controls.addEventListener('change', render);
transform();
//窗口大小变化事件
window.addEventListener('resize', onWindowResize, false);
}
function transform() {
let duration = 2000;
TWEEN.removeAll();
for (let i = 0; i < objects.length; i++) {
let object = objects[i];
let target = targets[i];
new TWEEN.Tween(object.position)
.to({ x: target.position.x, y: target.position.y, z: target.position.z }, Math.random() * duration + duration)
.easing(TWEEN.Easing.Exponential.InOut)
.start();
new TWEEN.Tween(object.rotation)
.to({ x: target.rotation.x, y: target.rotation.y, z: target.rotation.z }, Math.random() * duration + duration)
.easing(TWEEN.Easing.Exponential.InOut)
.start();
}
new TWEEN.Tween(this)
.to({}, duration * 2)
.onUpdate(render)
.start();
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
render();
}
//旋转动画
function animate() {
// 让场景通过x轴或者y轴旋转 & z
// scene.rotation.x += 0.001;
scene.rotation.y += 0.001;
requestAnimationFrame(animate);
TWEEN.update();
controls.update();
// 渲染循环
render();
}
function render() {
renderer.render(scene, camera);
}
</script>
<style>
html,
body {
height: 100%;
}
body {
background-color: #000000;
margin: 0;
overflow: hidden;
}
.element {
width: 140px;
height: 140px;
cursor: pointer;
box-shadow: 0px 0px 12px rgba(238, 196, 11, 0.5);
border: 2px solid #fff;
text-align: center;
cursor: default;
}
.element:hover {
box-shadow: 0px 0px 12px rgba(11, 250, 250, 0.85);
border: 2px solid rgba(127, 255, 255, 0.85);
}
.element img {
width: 140px;
height: 140px;
cursor: pointer;
object-fit: cover;
}
#music {
display: none;
}
</style>
</body>
</html>