-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.html
More file actions
661 lines (570 loc) · 17 KB
/
index.html
File metadata and controls
661 lines (570 loc) · 17 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
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
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="icon" type="image/x-icon" href="img/logo.ico" />
<title>ZY知识库-便签墙</title>
<style>
:root {
/* 过渡动画 */
--transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
--transition-fast: all 0.2s ease;
--transition-slow: all 0.5s ease;
}
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
background-image: linear-gradient(0deg, #eee 1px, transparent 0),
linear-gradient(90deg, #eee 1px, transparent 0);
background-size: 30px 30px;
color: #333;
min-height: 100dvh;
overflow: hidden;
}
body.is-mobile {
overflow-y: auto;
}
#board {
position: relative;
width: 100vw;
height: 100dvh;
overflow: hidden;
}
body.is-mobile #board {
height: auto;
min-height: 100dvh;
}
.card {
position: absolute;
width: 220px;
border-radius: 12px;
box-shadow: 0 16px 35px rgba(0, 0, 0, 0.2);
background: #fff;
border: 1px solid rgba(0, 0, 0, 0.08);
overflow: hidden;
opacity: 0;
transform-origin: center;
transition: transform 0.35s ease, opacity 0.35s ease, left 0.35s ease,
top 0.35s ease, width 0.35s ease, height 0.35s ease,
border-radius 0.35s ease;
}
.card.dragging {
transition: none;
box-shadow: 0 22px 45px rgba(0, 0, 0, 0.35);
}
.card.maximized {
box-shadow: 0 28px 60px rgba(0, 0, 0, 0.4);
}
.card-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 10px 12px;
background: rgba(255, 255, 255, 0.7);
cursor: grab;
user-select: none;
touch-action: pan-y;
}
.card-header.dragging {
cursor: grabbing;
}
.window-controls {
display: flex;
align-items: center;
gap: 6px;
}
.window-controls .control {
position: relative;
width: 12px;
height: 12px;
border-radius: 50%;
border: 1px solid rgba(0, 0, 0, 0.08);
background: #ccc;
cursor: pointer;
outline: none;
padding: 0;
display: inline-flex;
align-items: center;
justify-content: center;
}
.window-controls .control.close {
background: #ff5f57;
border-color: #e0443e;
}
.window-controls .control.minimize {
background: #febb2e;
border-color: #dea123;
}
.window-controls .control.maximize {
background: #28c840;
border-color: #1aab2c;
}
.window-controls .control::after {
content: '';
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
opacity: 0;
transition: opacity 0.2s ease;
}
.card-header:hover .window-controls .control::after {
opacity: 0.8;
}
.window-controls .control.close::after {
content: '×';
width: auto;
height: auto;
background: none;
font-size: 10px;
line-height: 1;
font-weight: 700;
color: rgba(0, 0, 0, 0.7);
}
.window-controls .control.minimize::after {
width: 6px;
height: 2px;
background: rgba(0, 0, 0, 0.6);
}
.window-controls .control.maximize::after {
width: 6px;
height: 6px;
background: linear-gradient(
45deg,
rgba(0, 0, 0, 0.6) 0%,
rgba(0, 0, 0, 0.6) 45%,
transparent 45%,
transparent 55%,
rgba(0, 0, 0, 0.6) 55%,
rgba(0, 0, 0, 0.6) 100%
);
}
.card-title {
font-size: 13px;
font-weight: 600;
color: rgba(0, 0, 0, 0.55);
padding-left: 10px;
flex: 1;
}
.card-body {
padding: 16px;
font-size: 16px;
line-height: 1.4;
font-weight: 600;
color: rgba(0, 0, 0, 0.72);
}
@media (max-width: 768px) {
.card {
width: 180px;
border-radius: 10px;
}
.card-body {
padding: 14px;
font-size: 14px;
}
.card-title {
font-size: 12px;
}
}
.github-corner {
position: fixed;
top: 0;
left: 0;
border: 0;
transform: scaleX(-1);
z-index: 1000;
}
.github-corner:hover svg {
fill: var(--primary-dark);
}
.github-corner svg {
fill: var(--primary-color);
color: white;
transition: var(--transition);
}
.github-corner:hover .octo-arm {
animation: octocat-wave 560ms ease-in-out;
}
@keyframes octocat-wave {
0%, 100% { transform: rotate(0); }
20%, 60% { transform: rotate(-25deg); }
40%, 80% { transform: rotate(10deg); }
}
</style>
</head>
<body>
<!-- GitHub 角标 -->
<a href="https://github.com/ZyPLJ/notes" target="_blank" aria-label="View source on Github"
class="github-corner">
<svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true" style="fill: #151513; color: #fff;">
<path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path>
<path
d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2"
fill="currentColor" class="octo-arm" style="transform-origin: 130px 106px;"></path>
<path
d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z"
fill="currentColor" class="octo-body"></path>
</svg>
</a>
<div id="board"></div>
<script>
const board = document.getElementById('board')
const messages = [
'保持好心情',
'多喝水哦',
'今天辛苦啦',
'早点休息',
'记得吃水果',
'加油,你可以的',
'祝你顺利',
'保持微笑呀',
'愿所有烦恼都消失',
'期待下一次见面',
'梦想总会实现',
'天气冷了,多穿衣服',
'记得给自己放松',
'每天都要元气满满',
'今天也要好好爱自己',
'适当休息一下'
]
const colors = [
'#ffe0e3',
'#c7f0ff',
'#ffd8a8',
'#d9f2d9',
'#e5d7ff',
'#f9f7d9',
'#d2f0f8',
'#ffd4f5'
]
const cardStates = new WeakMap()
// Reserve a very high层级给全屏卡片,避免被后续元素覆盖
const MAXIMIZED_LAYER = 1000000
let activeMaximizedCard = null
let isMobile =
window.matchMedia('(pointer: coarse)').matches ||
window.innerWidth <= 768
const maxCards = isMobile ? 120 : 180 // 限制 DOM 节点数量,减轻移动端压力
const initialCardCount = isMobile ? 18 : 30
const spawnInterval = isMobile ? 700 : 400
let zIndexCursor = 200
document.body.classList.toggle('is-mobile', isMobile)
function randomFrom(array) {
return array[Math.floor(Math.random() * array.length)]
}
function clamp(value, min, max) {
return Math.min(Math.max(value, min), max)
}
function applyTransform(card, state) {
const scale = state.scale ?? 1
const translateX = state.translateX ?? 0
const translateY = state.translateY ?? 0
const angle = state.angle ?? 0
card.style.transform = `translate(${translateX}px, ${translateY}px) scale(${scale}) rotate(${angle}deg)`
}
function bringToFront(card) {
if (card === activeMaximizedCard) {
card.style.zIndex = MAXIMIZED_LAYER
return
}
zIndexCursor += 1
if (activeMaximizedCard && zIndexCursor >= MAXIMIZED_LAYER) {
zIndexCursor = MAXIMIZED_LAYER - 1
}
card.style.zIndex = zIndexCursor
}
function setupCardInteractions(card) {
const header = card.querySelector('.card-header')
const closeBtn = card.querySelector('.control.close')
const minimizeBtn = card.querySelector('.control.minimize')
const maximizeBtn = card.querySelector('.control.maximize')
closeBtn.addEventListener('click', event => {
event.stopPropagation()
closeCard(card)
})
minimizeBtn.addEventListener('click', event => {
event.stopPropagation()
minimizeCard(card)
})
maximizeBtn.addEventListener('click', event => {
event.stopPropagation()
toggleMaximize(card)
})
header.addEventListener('pointerdown', event => {
if (event.pointerType === 'touch') return
startDrag(event, card)
})
card.addEventListener('pointerdown', () => {
bringToFront(card)
})
header.addEventListener('dblclick', event => {
if (!event.target.closest('.control')) {
toggleMaximize(card)
}
})
}
function closeCard(card) {
const state = cardStates.get(card)
if (!state || state.closing) return
if (card === activeMaximizedCard) {
activeMaximizedCard = null
}
state.closing = true
state.scale = 0.1
card.style.opacity = '0'
applyTransform(card, state)
const handleTransitionEnd = event => {
if (event.propertyName === 'opacity') {
card.removeEventListener('transitionend', handleTransitionEnd)
card.remove()
}
}
card.addEventListener('transitionend', handleTransitionEnd)
}
function minimizeCard(card) {
const state = cardStates.get(card)
if (!state || state.closing) return
// 最小化动画:缩小并淡出到底部,结束时移除节点释放内存
const runMinimize = () => {
state.closing = true
bringToFront(card)
const bottom = Math.max(window.innerHeight - 24, 0)
const targetLeft = clamp(
state.left,
16,
Math.max(window.innerWidth - card.offsetWidth - 16, 16)
)
state.left = targetLeft
state.top = bottom
state.scale = 0.1
state.angle = 0
card.style.left = `${targetLeft}px`
card.style.top = `${bottom}px`
card.style.opacity = '0.35'
applyTransform(card, state)
const handleTransitionEnd = event => {
if (event.propertyName === 'transform') {
card.removeEventListener('transitionend', handleTransitionEnd)
card.remove()
}
}
card.addEventListener('transitionend', handleTransitionEnd)
}
if (state.maximized) {
activeMaximizedCard = null
state.maximized = false
card.classList.remove('maximized')
card.style.borderRadius = '12px'
state.left = 0
state.top = 0
state.scale = 1
state.angle = 0
applyTransform(card, state)
requestAnimationFrame(() => {
requestAnimationFrame(runMinimize)
})
return
}
runMinimize()
}
function toggleMaximize(card) {
const state = cardStates.get(card)
if (!state || state.closing) return
if (state.maximized) {
restoreFromMaximize(card, state)
} else {
maximizeCard(card, state)
}
}
function maximizeCard(card, state) {
state.beforeMaximize = {
left: state.left,
top: state.top,
scale: state.scale ?? 1,
width: card.offsetWidth,
height: card.offsetHeight,
angle: state.angle ?? 0
}
card.classList.add('maximized')
card.style.left = '0px'
card.style.top = '0px'
card.style.width = `${window.innerWidth}px`
card.style.height = `${window.innerHeight}px`
card.style.borderRadius = '0'
state.left = 0
state.top = 0
state.scale = 1
state.angle = 0
applyTransform(card, state)
activeMaximizedCard = card
bringToFront(card)
state.maximized = true
}
function restoreFromMaximize(card, state) {
const previous = state.beforeMaximize
if (!previous) return
card.classList.remove('maximized')
card.style.left = `${previous.left}px`
card.style.top = `${previous.top}px`
card.style.width = `${previous.width}px`
card.style.height = `${previous.height}px`
card.style.borderRadius = '12px'
state.left = previous.left
state.top = previous.top
state.scale = previous.scale ?? 1
state.angle = previous.angle ?? state.angle ?? 0
applyTransform(card, state)
state.maximized = false
if (activeMaximizedCard === card) {
activeMaximizedCard = null
}
bringToFront(card)
state.lastPosition = { left: state.left, top: state.top }
setTimeout(() => {
if (!state.maximized) {
card.style.width = ''
card.style.height = ''
state.width = card.offsetWidth
state.height = card.offsetHeight
}
}, 360)
}
function startDrag(event, card) {
const control = event.target.closest('.control')
if (control) return
const state = cardStates.get(card)
if (!state || state.closing || state.maximized) return
// 鼠标拖拽使用 rAF 节流,避免频繁触发布局计算
event.preventDefault()
bringToFront(card)
const header = card.querySelector('.card-header')
card.classList.add('dragging')
header.classList.add('dragging')
state.dragging = true
state.dragOffsetX = event.clientX - state.left
state.dragOffsetY = event.clientY - state.top
let dragFrame = null
let pendingLeft = state.left
let pendingTop = state.top
const commitDrag = () => {
dragFrame = null
const maxLeft = Math.max(window.innerWidth - card.offsetWidth, 0)
const maxTop = Math.max(window.innerHeight - card.offsetHeight, 0)
state.left = clamp(pendingLeft, -card.offsetWidth * 0.4, maxLeft)
state.top = clamp(pendingTop, -card.offsetHeight * 0.4, maxTop)
card.style.left = `${state.left}px`
card.style.top = `${state.top}px`
}
const handlePointerMove = moveEvent => {
if (!state.dragging) return
pendingLeft = moveEvent.clientX - state.dragOffsetX
pendingTop = moveEvent.clientY - state.dragOffsetY
if (dragFrame === null) {
dragFrame = requestAnimationFrame(commitDrag)
}
}
const handlePointerUp = () => {
state.dragging = false
state.lastPosition = { left: state.left, top: state.top }
card.classList.remove('dragging')
header.classList.remove('dragging')
if (dragFrame !== null) {
cancelAnimationFrame(dragFrame)
commitDrag()
}
document.removeEventListener('pointermove', handlePointerMove)
document.removeEventListener('pointerup', handlePointerUp)
}
document.addEventListener('pointermove', handlePointerMove)
document.addEventListener('pointerup', handlePointerUp)
}
function createCard() {
const card = document.createElement('div')
card.className = 'card'
const color = randomFrom(colors)
const angleRange = isMobile ? 6 : 10
const angle = (Math.random() - 0.5) * angleRange
const cardWidth = isMobile ? 180 : 220
const cardHeight = isMobile ? 130 : 140
const horizontalMargin = isMobile ? 12 : 16
const verticalMargin = isMobile ? 12 : 20
const left =
horizontalMargin +
Math.random() *
Math.max(window.innerWidth - cardWidth - horizontalMargin * 2, 0)
const top =
verticalMargin +
Math.random() *
Math.max(window.innerHeight - cardHeight - verticalMargin * 2, 0)
card.style.background = color
card.style.left = `${left}px`
card.style.top = `${top}px`
if (activeMaximizedCard && zIndexCursor >= MAXIMIZED_LAYER - 2) {
zIndexCursor = MAXIMIZED_LAYER - 2
}
card.style.zIndex = ++zIndexCursor
card.innerHTML = `
<div class="card-header">
<div class="window-controls">
<button class="control close" type="button" aria-label="关闭"></button>
<button class="control minimize" type="button" aria-label="最小化"></button>
<button class="control maximize" type="button" aria-label="最大化"></button>
</div>
<div class="card-title">温馨提示</div>
</div>
<div class="card-body">${randomFrom(messages)}</div>
`
const state = {
angle,
scale: isMobile ? 0.85 : 0.7,
translateX: 0,
translateY: 0,
left,
top,
maximized: false,
closing: false,
lastPosition: { left, top }
}
cardStates.set(card, state)
applyTransform(card, state)
board.appendChild(card)
state.width = card.offsetWidth
state.height = card.offsetHeight
requestAnimationFrame(() => {
state.scale = 1
applyTransform(card, state)
card.style.opacity = '1'
})
setupCardInteractions(card)
if (board.children.length > maxCards) {
const oldest = board.firstElementChild
if (oldest && oldest !== card) {
oldest.remove()
}
}
}
for (let i = 0; i < initialCardCount; i++) {
setTimeout(createCard, i * (isMobile ? 60 : 40))
}
setInterval(() => {
createCard()
}, spawnInterval)
window.addEventListener('resize', () => {
isMobile =
window.matchMedia('(pointer: coarse)').matches ||
window.innerWidth <= 768
// 视口变化时重新切换移动端模式,并同步全屏卡片的宽高
document.body.classList.toggle('is-mobile', isMobile)
document.querySelectorAll('.card.maximized').forEach(card => {
card.style.width = `${window.innerWidth}px`
card.style.height = `${window.innerHeight}px`
})
})
</script>
</body>
</html>