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

Skip to content

Commit 8a3d2cf

Browse files
committed
Added Mouse Move Shadow (wesbos#16)
1 parent 3ebb118 commit 8a3d2cf

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

16 - Mouse Move Shadow/index-start.html

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

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

0 commit comments

Comments
 (0)