Visitar URL original
Day 16 Complete · wesbos/JavaScript30@bd8262d · GitHub
Skip to content

Commit bd8262d

Browse files
committed
Day 16 Complete
Had fun with mouse move scroll effects!!!!
1 parent f080df8 commit bd8262d

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

‎16 - Mouse Move Shadow/index-start.html‎

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

3333
<script>
34+
const hero = document.querySelector('.hero');
35+
const text = document.querySelector('h1');
36+
const walk = 500; //100px
37+
38+
function shadow(e)
39+
{
40+
const width = hero.offsetWidth;
41+
const height = hero.offsetHeight;
42+
let x = e.offsetX;
43+
let y = e.offsetY;
44+
45+
if(this !== e.target)
46+
{
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 / width * walk) - (walk / 2));
53+
54+
text.style.textShadow = `
55+
${xWalk}px ${yWalk}px 0 rgba(255,0,255,0.7),
56+
${xWalk * -1}px ${yWalk}px 0 rgba(0,255,255,0.7),
57+
${yWalk}px ${xWalk * -1}px 0 rgba(0,255,0,0.7),
58+
${yWalk * -1}px ${xWalk}px 0 rgba(0,0,255,0.7)
59+
`;
60+
61+
}
62+
63+
hero.addEventListener('mousemove', shadow);
3464
</script>
3565
</body>
3666
</html>

0 commit comments

Comments
 (0)