Skip to content

Commit c49f086

Browse files
committed
Completed Day 16 of JavaScript 30
1 parent 68151ec commit c49f086

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

16 - Mouse Move Shadow/index-start.html

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,32 @@ <h1 contenteditable>🔥WOAH!</h1>
3131
</style>
3232

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

0 commit comments

Comments
 (0)