-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbilibili.html
90 lines (80 loc) · 1.96 KB
/
bilibili.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
<!DOCTYPE html>
<html lang="charset">
<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>Document</title>
<style>
body,
html {
margin: 0;
width: 100%;
height: 100%;
}
header {
height: 160px;
width: 100%;
position: relative;
overflow: hidden;
}
header > div {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
--offset: 0px;
--blur: 2px;
}
header > div > img {
display: block;
width: 110%;
height: 100%;
object-fit: cover;
transform: translateX(var(--offset));
filter: blur(var(--blur));
}
</style>
</head>
<body>
<header>
<div>
<img src="https://assets.codepen.io/2002878/bilibili-autumn-1.png" />
</div>
<div>
<img src="https://assets.codepen.io/2002878/bilibili-autumn-2.png" />
</div>
<div>
<img src="https://assets.codepen.io/2002878/bilibili-autumn-3.png" />
</div>
<div>
<img src="https://assets.codepen.io/2002878/bilibili-autumn-4.png" />
</div>
<div>
<img src="https://assets.codepen.io/2002878/bilibili-autumn-5.png" />
</div>
<div>
<img src="https://assets.codepen.io/2002878/bilibili-autumn-6.png" />
</div>
</header>
<script>
const images = document.querySelectorAll('header > div > img')
document.querySelector('header').addEventListener('mousemove', (e) => {
let percentage = e.clientX / window.outerWidth
let offset = 10 * percentage
let blur = 20
for (let [index, image] of images.entries()) {
offset *= 1.3
console.log(offset)
let blurValue = Math.pow(index / images.length - percentage, 2) * blur
image.style.setProperty('--offset', `${offset}px`)
image.style.setProperty('--blur', `${blurValue}px`)
}
})
</script>
</body>
</html>