We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 68151ec commit c49f086Copy full SHA for c49f086
1 file changed
16 - Mouse Move Shadow/index-start.html
@@ -31,6 +31,32 @@ <h1 contenteditable>🔥WOAH!</h1>
31
</style>
32
33
<script>
34
+ const hero = document.querySelector('.hero');
35
+ const text = hero.querySelector('h1');
36
+ const walk = 500; // 100px
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 = x + e.target.offsetLeft;
44
+ y = 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
+ console.log(xWalk, yWalk);
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
</script>
61
</body>
62
</html>
0 commit comments