Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b9a23a8

Browse files
committed
16th exercise done
1 parent ea512b4 commit b9a23a8

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

16 - Mouse Move Shadow/index-start.html

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

3333
<script>
34+
const hero = document.querySelector('.hero');
35+
const text = hero.querySelector('h1');
36+
const walk = 100;
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 += e.target.offsetLeft;
44+
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+
50+
text.style.textShadow = `${xWalk}px ${yWalk}px 0 rgba(255,0,255,0.7),
51+
${xWalk * -1}px ${yWalk * -1}px 0 rgba(0,255,255,0.7),
52+
${yWalk}px ${xWalk * -1}px 0 rgba(0,255,0,0.7),
53+
${yWalk * -1}px ${xWalk}px 0 rgba(0,0,255,0.7)
54+
55+
`;
56+
}
57+
58+
hero.addEventListener('mousemove', shadow);
3459
</script>
3560
</body>
3661
</html>

0 commit comments

Comments
 (0)