Skip to content

Commit c4b75c8

Browse files
committed
Finished wesbos#16
1 parent 0a42e04 commit c4b75c8

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed

16 - Mouse Move Shadow/index-start.html

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ <h1 contenteditable>🔥WOAH!</h1>
1212

1313
<style>
1414
html {
15-
color:black;
15+
color:#444;
1616
font-family: sans-serif;
1717
}
1818

@@ -25,16 +25,51 @@ <h1 contenteditable>🔥WOAH!</h1>
2525
display:flex;
2626
justify-content: center;
2727
align-items: center;
28-
color:black;
28+
color:#444;
2929
}
3030

3131
h1 {
32-
text-shadow: 10px 10px 0 rgba(0,0,0,1);
32+
text-shadow: 10px 10px 0 rgba(0,0,0,.3);
3333
font-size: 100px;
3434
}
3535
</style>
3636

3737
<script>
38+
const hero = document.querySelector('.hero');
39+
const text = hero.querySelector('h1');
40+
const walk = 150;
41+
42+
function shadow(e) {
43+
// console.log(e);
44+
45+
// const width = hero.offsetWidth;
46+
// const height = hero.offsetHeight;
47+
48+
const { offsetWidth: width, offsetHeight: height } = hero;
49+
let { offsetX: x, offsetY: y } = e;
50+
51+
if (this !== e.target) {
52+
x = x + e.target.offsetLeft;
53+
y = y + e.target.offsetTop;
54+
}
55+
56+
// console.log(x, y);
57+
58+
// rather than going from 0 to 100,
59+
// go from -50 to +50.
60+
const xWalk = Math.round((x / width * walk) - (walk / 2));
61+
const yWalk = Math.round((y / height * walk) - (walk / 2));
62+
63+
text.style.textShadow = `
64+
${xWalk}px ${yWalk}px 0 hsla(0, 100%, 0%, 0.3),
65+
${xWalk * -1}px ${yWalk}px 0 hsla(255, 100%, 50%, 0.8),
66+
${xWalk}px ${yWalk * -1}px 0 hsla(50, 100%, 50%, 0.8),
67+
${xWalk * -1}px ${yWalk * -1}px 0 hsla(10, 100%, 50%, 0.8)
68+
`;
69+
}
70+
71+
hero.addEventListener('mousemove', shadow);
3872
</script>
73+
3974
</body>
4075
</html>

0 commit comments

Comments
 (0)