@@ -31,6 +31,33 @@ <h1 contenteditable>🔥WOAH!</h1>
31
31
</ style >
32
32
33
33
< 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
+
34
61
</ script >
35
62
</ body >
36
63
</ html >
0 commit comments