-
Notifications
You must be signed in to change notification settings - Fork 0
/
macDock.html
111 lines (101 loc) · 2.55 KB
/
macDock.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>mac dock</title>
<style>
html {
font-size: 10px;
}
body {
margin: 0;
padding: 0;
display: flex;
width: 100%;
min-height: 100vh;
overflow: hidden;
align-items: flex-end;
}
.glass {
width: 100%;
height: 10rem;
background: #eee;
display: flex;
justify-content: center;
/* align-items: center; */
}
.dock {
--scale: 1;
list-style: none;
margin: 0;
/* padding: 0.5rem; */
display: flex;
justify-content: center;
align-items: center;
}
.dock li {
font-size: calc(5rem*var(--scale));
padding: 0.5rem;
position: relative;
top: calc((5rem * var(--scale)- 5rem) /2 * -1);
cursor: default;
/* 加上动画之后很卡 */
/* transition: 15ms all ease-out; */
}
</style>
</head>
<body>
<div class="glass">
<ul class="dock">
<li>😀</li>
<li>😃</li>
<li>😄</li>
<li>😁</li>
<li>😅</li>
<li>😆</li>
<li>😂</li>
<li>🤣</li>
<li>🀄️</li>
<li>🖥</li>
<li>🗽</li>
<li>🎮</li>
<li>🌎</li>
<li>🐻</li>
</ul>
</div>
<script>
let li = document.querySelectorAll('.dock li')
li.forEach((li) => {
li.addEventListener('mousemove', e => {
let item = e.target
let itemRect = item.getBoundingClientRect()
// 计算光标在元素上的偏移量
let offset = Math.abs(e.clientX - itemRect.left) / itemRect.width
// console.log(offset,offset - 1,Math.abs(offset - 1))
// console.log(e.clientX - itemRect.left,Math.abs(e.clientX - itemRect.left))
let prev = item.previousElementSibling || null
let next = item.nextElementSibling || null
let scale = 0.6
if (prev) {
prev.style.setProperty('--scale', 1 + scale * Math.abs(offset - 1))
}
item.style.setProperty('--scale', 1 + scale)
if (next) {
next.style.setProperty('--scale', 1 + scale * offset)
}
})
// li.addEventListener('mouselevel')
})
document.querySelector('.dock').addEventListener('mouseleave', () => {
resetScale()
})
function resetScale() {
li.forEach(li => {
li.style.setProperty('--scale', 1)
})
}
</script>
</body>
</html>