Visitar URL original
Adds Day 16 Fini6 Fini6 Fini6 Fini6 Fini6 Finished Code. · wesbos/JavaScript30@08f2e4b · GitHub
Skip to content

Commit 08f2e4b

Browse files
author
Rob Andrews
committed
Adds Day 16 Fini6 Fini6 Fini6 Fini6 Fini6 Finished Code.
1 parent f6fcc65 commit 08f2e4b

1 file changed

Lines changed: 25 additions & 1 deletion

File tree

‎16 - Mouse Move Shadow/index-start.html‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,36 @@ <h1 contenteditable>🔥WOAH!</h1>
2525
}
2626

2727
h1 {
28-
text-shadow: 10px 10px 0 rgba(0,0,0,1);
2928
font-size: 100px;
3029
}
3130
</style>
3231

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

0 commit comments

Comments
 (0)