Visitar URL original
Finished #16 mouse move · jdlawrence/JavaScript30@8c148dd · GitHub
Skip to content

Commit 8c148dd

Browse files
committed
Finished wesbos#16 mouse move
1 parent 257348a commit 8c148dd

1 file changed

Lines changed: 45 additions & 20 deletions

File tree

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,61 @@
11
<!DOCTYPE html>
22
<html lang="en">
3+
34
<head>
45
<meta charset="UTF-8">
56
<title>Mouse Shadow</title>
67
</head>
8+
79
<body>
810

911
<div class="hero">
1012
<h1 contenteditable>🔥WOAH!</h1>
1113
</div>
1214

1315
<style>
14-
html {
15-
color:black;
16-
font-family: sans-serif;
17-
}
18-
19-
.hero {
20-
min-height: 100vh;
21-
display:flex;
22-
justify-content: center;
23-
align-items: center;
24-
color:black;
25-
}
26-
27-
h1 {
28-
text-shadow: 10px 10px 0 rgba(0,0,0,1);
29-
font-size: 100px;
30-
}
16+
html {
17+
color: black;
18+
font-family: sans-serif;
19+
}
20+
21+
.hero {
22+
min-height: 100vh;
23+
display: flex;
24+
justify-content: center;
25+
align-items: center;
26+
color: black;
27+
}
28+
29+
h1 {
30+
text-shadow: 10px 10px 30px rgba(0, 0, 0, 1);
31+
font-size: 100px;
32+
}
3133
</style>
3234

33-
<script>
34-
</script>
35+
<script>
36+
const hero = document.querySelector('.hero');
37+
const text = document.querySelector('h1');
38+
const walk = 100;
39+
40+
function shadow(e) {
41+
const { offsetWidth: width, offsetHeight: height } = hero;
42+
let { offsetX: x, offsetY: y } = e;
43+
44+
if (this !== e.target) {
45+
x += e.target.offsetLeft;
46+
y += e.target.offsetTop;
47+
}
48+
49+
const xWalk = (x / width * 100) - (walk / 2);
50+
const yWalk = (y / height * 100) - (walk / 2);
51+
52+
text.style.textShadow = `${xWalk}px ${yWalk}px 30px rgba(0,140,0,1)`;
53+
console.log(xWalk, yWalk);
54+
}
55+
56+
hero.addEventListener('mousemove', shadow);
57+
58+
</script>
3559
</body>
36-
</html>
60+
61+
</html>

0 commit comments

Comments
 (0)