Skip to content

Commit 18ed523

Browse files
author
Sergey Royz
committed
16
1 parent 6e04fd5 commit 18ed523

File tree

2 files changed

+65
-40
lines changed

2 files changed

+65
-40
lines changed

16 - Mouse Move Shadow/index-START.html

Lines changed: 0 additions & 40 deletions
This file was deleted.

16 - Mouse Move Shadow/index.html

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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+
html {
15+
color: black;
16+
font-family: sans-serif;
17+
}
18+
19+
body {
20+
margin: 0;
21+
}
22+
23+
.hero {
24+
min-height: 100vh;
25+
display: flex;
26+
justify-content: center;
27+
align-items: center;
28+
color: black;
29+
}
30+
31+
h1 {
32+
text-shadow: 10px 10px 0 rgba(0,0,0,1);
33+
font-size: 100px;
34+
}
35+
</style>
36+
37+
<script>
38+
39+
const hero = document.querySelector(".hero");
40+
const text = hero.querySelector("h1");
41+
const walk = 100;
42+
43+
function onMouseMove(e) {
44+
const { offsetWidth: width, offsetHeight: height } = hero;
45+
let { offsetX: x, offsetY: y } = e;
46+
47+
if (this != e.target) {
48+
x += e.target.offsetLeft;
49+
y += e.target.offsetTop;
50+
}
51+
52+
const xWalk = (x / width * walk) - (walk / 2);
53+
const yWalk = (y / height * walk) - (walk / 2);
54+
55+
text.style.textShadow = `${xWalk}px ${yWalk}px 0 red`;
56+
57+
58+
}
59+
60+
hero.addEventListener('mousemove', onMouseMove);
61+
62+
63+
</script>
64+
</body>
65+
</html>

0 commit comments

Comments
 (0)