Skip to content

Commit b0c7ccc

Browse files
author
Alexander Besse
committed
wesbos#16 Completed.
1 parent c34ae9b commit b0c7ccc

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

16 - Mouse Move Shadow/index-START.html

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,28 @@ <h1 contenteditable>🔥WOAH!</h1>
3535
</style>
3636

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

0 commit comments

Comments
 (0)