-
Notifications
You must be signed in to change notification settings - Fork 92
/
Copy pathNo title.html
451 lines (368 loc) · 11.3 KB
/
No title.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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
<!DOCTYPE html>
<html lang='en' onselectstart='return false'>
<head>
<meta charset='utf-8' />
<style>
li,
ul,
div,
html,
body{
margin: 0;
padding: 0;
}
html,
body{ height: 100% }
li{ list-style-type: none }
.wrap{
height: 100%;
overflow: hidden;
perspective: 800px;
}
#box{
top: 50%;
left: 50%;
width: 0;
height: 0;
position: relative;
transform-style: preserve-3d;
transform: translateZ(-1600px);
z-index: 1;
}
#box li{
top: -80px;
left: -60px;
width: 120px;
height: 160px;
position: absolute;
text-align: center;
line-height: 160px;
background-color: rgba(5,100,80,0.2);
border: 1px solid rgba(125,255,255,0.25);
box-shadow: 0 0 15px rgba(0,255,255,0.5);
cursor: pointer;
}
#box li span{
font-size: 28px;
font-weight: blod;
text-shadow: 2px 2px 5px black;
color: #efebef;
}
.mask{
width: 100%;
height: 100%;
background: url('bg_mask.jpg') no-repeat center;
background-size: cover;
filter: blur(5px);
}
.mask > .bg-mask{
width: 100%;
height: 100%;
background: #000;
opacity: 0.25;
}
</style>
</head>
<body>
<div class="wrap">
<ul id="box"></ul>
<div class="mask">
<div class="bg-mask"></div>
</div>
</div>
<script src='jquery-2.2.4.js'></script>
<script>
// 开启一个独立的空间避免全局变量污染
(function(){
let
idx,
timer,
// 存放li 元素
liElem,
// 存放span 元素
spanElem,
// 记录布局类型
currentStyle,
// 鼠标X、Y坐标值
oldCoordX,
oldCoordY,
nowCoordX,
nowCoordY,
// li 元素水平、垂直、纵深方向偏移位
offsetStepX,
offsetStepY,
offsetStepZ,
// li 元素的坐标
liElemCoordX,
liElemCoordY,
liElemCoordZ,
// 鼠标X、Y差值
minusX = 0,
minusY = 0,
// X、Y偏移度数
liElemDegX = 0,
liElemDegY = 0,
// li 元素的最大个数
liElemMaxNum = 162,
// li 元素 水平、垂直铺放的最大个数
liElemRowMaxNum = 5,
liElemColMaxNum = 5,
// li 元素水平、垂直、纵深方向的最大间隔距离
liElemOffsetX = 350,
liElemOffsetY = 350,
liElemOffsetZ = 350,
// li 元素默认景深
liElemDepDefault = -1000,
// 避免覆盖默认景深值
depDefault = liElemDepDefault-600;
// 避免第一次拖动发生错位
liElemDepZ = liElemDepDefault-600,
// 单个方阵中 li 元素的总个数
aScreenNum = liElemRowMaxNum*liElemColMaxNum,
// li 元素纵深方向的最在间隔距离
liElemDepMaxDist = parseInt(liElemMaxNum/aScreenNum),
// 计算第一个li 元素的坐标点
liElemFristSiteX = parseInt('-'+liElemRowMaxNum/2)*liElemOffsetX,
liElemFristSiteY = parseInt('-'+liElemColMaxNum/2)*liElemOffsetY,
liElemFristSiteZ = parseInt('-'+liElemDepMaxDist/2)*liElemOffsetZ,
// 文本内容
data = ['Grid','Helix','Chaotic','Sphere','Three','Geome','Curve','Random'];
// 指定一个区间,获取一个随机数
randomFrom = (lowerValue,upperValue) =>{
return Math.floor(Math.random()*(upperValue-lowerValue+1)+lowerValue);
}
// 方阵
gridLayout = _ =>{
let arr = [...Array(liElemMaxNum).keys()];
$('#box li').each(i =>{
// 数组的索引
let idx = randomFrom(0,arr.length-1);
// 计算li 元素 水平、垂直、纵深方向的偏移位
offsetStepX = ((i%aScreenNum)%liElemRowMaxNum)*liElemOffsetX;
offsetStepY = parseInt((i%aScreenNum)/liElemColMaxNum)*liElemOffsetY;
offsetStepZ = parseInt(i/aScreenNum)*liElemOffsetZ;
// 计算当前li 元素的坐标值
liElemCoordX = liElemFristSiteX+offsetStepX;
liElemCoordY = liElemFristSiteY+offsetStepY;
liElemCoordZ = liElemFristSiteZ+offsetStepZ;
$('#box li').eq(arr[idx]).css({
"transform":`translate3d(${liElemCoordX}px,${liElemCoordY}px,${liElemCoordZ}px)`,
"transition": "4s ease-in-out"
})
// 删除数组中的值
arr.splice(idx,1);
}); currentStyle = gridLayout;
}
// 螺旋
helixLayout = _ =>{
let arr = [...Array(liElemMaxNum).keys()];
$('#box li').each(i =>{
let idx = randomFrom(0,arr.length-1);
let liElemDegY = 10*i;
let liElemDepY = -10*parseInt(liElemMaxNum/2)+10*i;
$('#box li').eq(arr[idx]).css({
"transform":`rotateY(${liElemDegY}deg) translateY(${liElemDepY}px) translateZ(${Math.abs(liElemDepDefault)}px)`,
"transition": "4s ease-in-out"
})
// 删除数组中的值
arr.splice(idx,1)
}); currentStyle = helixLayout;
}
// 球形
sphereLayout = _ =>{
let arr = [...Array(liElemMaxNum).keys()];
$('#box li').each(i =>{
let idx = randomFrom(0,arr.length-1);
let liElemDegY = 3*i;
let liElemDegX = 30*i;
$('#box li').eq(arr[idx]).css({
"transform":`rotateY(${liElemDegY}deg) rotateX(${liElemDegX}deg) translateZ(${Math.abs(liElemDepDefault)}px)`,
"transition": "4s ease-in-out"
})
// 删除数组中的值
arr.splice(idx,1)
}); currentStyle = sphereLayout;
}
// 三体
threeLayout = _ =>{
let arr = [...Array(liElemMaxNum).keys()];
$('#box li').each(i =>{
let idx = randomFrom(0,arr.length-1);
let liElemDegY = 3*i;
let liElemDegX = 60*i;
$('#box li').eq(arr[idx]).css({
"transform":`rotateY(${liElemDegY}deg) rotateX(${liElemDegX}deg) translateZ(${Math.abs(liElemDepDefault)}px)`,
"transition": "4s ease-in-out"
})
// 删除数组中的值
arr.splice(idx,1)
}); currentStyle = threeLayout;
}
// 几何
geomeLayout = _ =>{
let arr = [...Array(liElemMaxNum).keys()];
$('#box li').each(i =>{
let idx = randomFrom(0,arr.length-1);
let liElemDegY = 8.9*i;
let liElemDegX = 2.9*i;
$('#box li').eq(arr[idx]).css({
"transform":`rotateY(${liElemDegY}deg) rotateX(${liElemDegX}deg) translateZ(${Math.abs(liElemDepDefault)}px)`,
"transition": "4s ease-in-out"
})
// 删除数组中的值
arr.splice(idx,1)
}); currentStyle = geomeLayout;
}
// 曲线
curveLayout = _ =>{
let arr = [...Array(liElemMaxNum).keys()];
$('#box li').each(i =>{
let idx = randomFrom(0,arr.length-1);
let liElemDegY = 1*i;
let liElemDegX = 2*i;
$('#box li').eq(arr[idx]).css({
"transform":`rotateY(${liElemDegY}deg) rotateX(${liElemDegX}deg) translateZ(${liElemDepDefault}px)`,
"transition": "4s ease-in-out"
})
// 删除数组中的值
arr.splice(idx,1)
}); currentStyle = curveLayout;
}
// 随机
chaoticLayout = _ =>{
$('#box li').each(function(i){
// 随机生成li 元素的坐标点
liElemCoordX = (Math.random()-0.5)*3000;
liElemCoordY = (Math.random()-0.5)*3000;
liElemCoordZ = (Math.random()-0.5)*3000;
$(this).css({
"transform":`translate3d(${liElemCoordX}px,${liElemCoordY}px,${liElemCoordZ}px)`,
"transition": "4s ease-in-out"
})
}); currentStyle = chaoticLayout;
}
function main(){
$([...Array(liElemMaxNum).keys()]).each(i =>{
// 创建一个li 元素
liElem = $('<li></li>');
let idx = randomFrom(0,data.length-1);
// 创建一个span 元素
spanElem = $(`<span>${data[idx]}</span>`);
liElem.append(spanElem);
// 设置span 中的文本颜色
spanElem.css('color',`rgb(${randomFrom(100,255)},${randomFrom(100,255)},${randomFrom(100,255)})`);
// 将已创建的li 元素添加至容器中
$('#box').append(liElem);
})
// 布局类型
layoutStyle = [gridLayout, helixLayout, chaoticLayout, sphereLayout,
threeLayout, geomeLayout, curveLayout];
// 鼠标移入移出效果
$('#box li').hover(function(){
$(this).css('border','1px solid rgba(125,255,255,0.75)');
$(this).css('boxShadow','0 0 15px rgba(0,255,255,0.75)');
$(this).css('transition','0s');
},function(){
$(this).css('border','1px solid rgba(125,255,255,0.25)');
$(this).css('boxShadow','0 0 15px rgba(0,255,255,0.5)');
$(this).css('transition','0s');
})
// 鼠标点击,切换布局
$('#box li').click(function(){
switch($(this).text()){
case 'Grid': gridLayout(); break;
case 'Helix': helixLayout(); break;
case 'Three': threeLayout(); break;
case 'Geome': geomeLayout(); break;
case 'Curve': curveLayout(); break;
case 'Sphere': sphereLayout(); break;
case 'Chaotic': chaoticLayout(); break;
default:
while(true){
idx = randomFrom(0,layoutStyle.length-1);
if(layoutStyle[idx] != currentStyle){
return layoutStyle[idx]();
}
}
break;
}
})
// 鼠标拖动与滚轮效果
$(document).mousedown(function(event){
event = event || window.event;
// 上一个点的X、Y坐标
oldCoordX = event.clientX;
oldCoordY = event.clientY;
$(this).on('mousemove',event =>{
event = event || window.event;
// 若上一个定时器存在,则将其删除
timer && clearInterval(timer);
// 当前点的X、Y坐标
nowCoordX = event.clientX;
nowCoordY = event.clientY;
// 计算机X、Y差值
minusX = nowCoordX - oldCoordX;
minusY = nowCoordY - oldCoordY;
// 更新上一个点的X、Y坐标值
oldCoordX = nowCoordX;
oldCoordY = nowCoordY;
// 计算X、Y轴的移动度数
liElemDegX -= minusY*0.1;
liElemDegY += minusX*0.1;
$('#box').css({
"transform":`translateZ(${liElemDepZ}px) rotateX(${liElemDegX}deg) rotateY(${liElemDegY}deg)`
})
}).mouseup(_ =>{
// 当鼠标弹起解除移动
$(document).off('mousemove');
// 若上一个定时器存在,则将其删除
timer && clearInterval(timer);
// 鼠标弹起后有缓动效果
timer = setInterval(_ => {
// 缓动差值
minusX *= 0.95;
minusY *= 0.95;
// 计算X、Y轴的移动度数
liElemDegX -= minusY*0.1;
liElemDegY += minusX*0.1;
// 当差值超出指定范围时,则清除定时器
Math.abs(minusX)<0.05
&& Math.abs(minusY)<0.05
&& clearInterval(timer);
$('#box').css({
"transform":`translateZ(${liElemDepZ}px) rotateX(${liElemDegX}deg) rotateY(${liElemDegY}deg)`
})
}, 12);
})
}).on('mousewheel DOMMouseScroll',e =>{
// 若上一个定时器存在,则将其删除
timer && clearInterval(timer);
// 获取鼠标滚动方向
let step = (e.originalEvent.wheelDelta
&& (e.originalEvent.wheelDelta >0?1:-1))
|| (e.originalEvent.detail && (e.originalEvent.detail >0?-1:1));
// 计算滚轮滚动时Z 轴景深的步长
liElemDepZ = depDefault += step*90;
$('#box').css({
"transform":`translateZ(${liElemDepZ}px) rotateX(${liElemDegX}deg) rotateY(${liElemDegY}deg)`
})
// 设置缓动效果
timer = setInterval(_ => {
// 缓动步长
step *= 0.6;
liElemDepZ += step*80;
Math.abs(step) < 0.000005
&& clearInterval(timer);
$('#box').css({
"transform":`translateZ(${liElemDepZ}px) rotateX(${liElemDegX}deg) rotateY(${liElemDegY}deg)`
})
}, 12);
})
// 加载布局
setTimeout(gridLayout,1000);
}
main();
})();
</script>
</body>
</html>