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

Skip to content

Commit f8936d0

Browse files
committed
complete mouse move
1 parent 12248d4 commit f8936d0

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

16 - Mouse Move Shadow/index-start.html

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

3333
<script>
34+
const hero = document.querySelector('.hero');
35+
const text = hero.querySelector('h1');
36+
const walk = 50; // 500 = 100px
37+
38+
function shadow(e) {
39+
const { offsetWidth: width, offsetHeight: height } = hero;
40+
let { offsetX: x, offsetY: y } = e;
41+
42+
// to prevent using coordinates when the target changes to h1
43+
if (this !== e.target) {
44+
x = x + e.target.offsetLeft;
45+
y = y + e.target.offsetTop;
46+
}
47+
48+
const xWalk = Math.round((x / width * walk) - (walk / 2));
49+
const yWalk = Math.round((y / height * walk) - (walk / 2));
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);
60+
3461
</script>
3562
</body>
3663
</html>

0 commit comments

Comments
 (0)