# macOS之Docker栏效果
html
<div class="glass">
<ul class="dock">
<li>😀</li>
<li>😘</li>
<li>😂</li>
<li>😎</li>
<li>🤪</li>
<li>😃</li>
<li>🤗</li>
</ul>
</div>
</body>
</html>
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
css
html {
font-size: 15px;
}
body {
margin: 0;
padding: 0;
display: flex;
width: 100%;
min-height: 100vh;
overflow: hidden;
align-items: flex-end;
}
.glass {
width: 100%;
height: 8rem;
background-color: #eee;
display: flex;
justify-content: center;
}
.dock {
--scale: 1;
list-style: none;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
}
.dock li {
font-size: calc(6rem * var(--scale));
padding: 0 .5rem;
cursor: default;
position: relative;
top: calc((6rem * var(--scale) - 6rem) / 2 * -1 );
transition: 15ms all ease-out;
}
.dock li.loading {
animation: 1s loading ease-in infinite;
}
@keyframes loading {
0%, 100% {
transform: translateY(0px);
}
60% {
transform: translateY(-40px);
}
}
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
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
js
document.querySelectorAll('.dock li').forEach(li => {
//增加点击效果
li.addEventListener('click', e => {
console.log('e', e);
// li.classList.remove('loading')
document.querySelectorAll('.dock li').forEach(i => i.classList.remove('loading'));
e.currentTarget.classList.add('loading');
});
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);
//初始化一个放大变量
let scale = 0.6;
//每次先重置变化
resetScale();
let prev = item.previousElementSibling || null; //获取前一个图标
let next = item.nextElementSibling || null; //获取后一个图标
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)
}
})
});
document.querySelector('.dock').addEventListener('mouseleave', () => {
resetScale();
})
//重置scale为1
function resetScale() {
document.querySelectorAll('.dock li').forEach(li => {
li.style.setProperty('--scale', 1)
})
}
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
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