Skip to content

Commit 2e1fd61

Browse files
committed
Add pre-video attempt at 16 - Mouse Move Shadow
1 parent b54981d commit 2e1fd61

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Mouse Shadow</title>
6+
</head>
7+
<body>
8+
9+
<div class="hero">
10+
<h1 contenteditable>🔥WOAH!</h1>
11+
</div>
12+
13+
<style>
14+
15+
:root {
16+
--shadowOneX: 10px;
17+
--shadowOneY: 10px;
18+
--shadowTwoX: -10px;
19+
--shadowTwoY: 10px;
20+
--shadowThreeX: 10px;
21+
--shadowThreeY: -10px;
22+
--shadowFourX: -10px;
23+
--shadowFourY: -10px;
24+
}
25+
26+
html {
27+
color:black;
28+
font-family: sans-serif;
29+
}
30+
31+
.hero {
32+
min-height: 100vh;
33+
display:flex;
34+
justify-content: center;
35+
align-items: center;
36+
color:black;
37+
}
38+
39+
h1 {
40+
text-shadow: var(--shadowOneX) var(--shadowOneY) 0 rgba(0,0,0,1), var(--shadowTwoX) var(--shadowTwoY) 0 blue, var(--shadowThreeX) var(--shadowThreeY) 0 green, var(--shadowFourX) var(--shadowFourY) 0 orange;
41+
font-size: 100px;
42+
}
43+
</style>
44+
45+
<script>
46+
const hero = document.querySelector('.hero');
47+
48+
function update(event) {
49+
const maxX = window.screen.availWidth;
50+
const maxY = window.screen.availHeight;
51+
const mouseX = event.screenX;
52+
const center = {x: maxX / 2, y: maxY / 2};
53+
const mouseY = event.screenY;
54+
const constraint = 200
55+
const shadowX = ((mouseX - center.x)/ maxX) * constraint;
56+
const shadowY = ((mouseY - center.y) / maxY ) * constraint;
57+
document.documentElement.style.setProperty(
58+
'--shadowOneX', `${shadowX}px`
59+
);
60+
document.documentElement.style.setProperty(
61+
'--shadowOneY', `${shadowY}px`
62+
);
63+
document.documentElement.style.setProperty(
64+
'--shadowTwoX', `${-shadowX}px`
65+
);
66+
document.documentElement.style.setProperty(
67+
'--shadowTwoY', `${shadowY}px`
68+
);
69+
document.documentElement.style.setProperty(
70+
'--shadowThreeX', `${shadowX}px`
71+
);
72+
document.documentElement.style.setProperty(
73+
'--shadowThreeY', `${-shadowY}px`
74+
);
75+
document.documentElement.style.setProperty(
76+
'--shadowFourX', `${-shadowX}px`
77+
);
78+
document.documentElement.style.setProperty(
79+
'--shadowFourY', `${-shadowY}px`
80+
);
81+
}
82+
83+
hero.addEventListener('mousemove', update);
84+
</script>
85+
</body>
86+
</html>

0 commit comments

Comments
 (0)