File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+ < head >
4+ < meta charset ="UTF-8 ">
5+ < title > Mouse Shadow</ title >
6+ </ head >
7+ < body >
8+
9+ < div class ="hero ">
10+ < h1 contenteditable > 🔥WOAH!</ h1 >
11+ </ div >
12+
13+ < style >
14+ html {
15+ color : black;
16+ font-family : sans-serif;
17+ }
18+
19+ .hero {
20+ min-height : 100vh ;
21+ display : flex;
22+ justify-content : center;
23+ align-items : center;
24+ color : black;
25+ }
26+
27+ h1 {
28+ text-shadow : 10px 10px 0 rgba (0 , 0 , 0 , 1 );
29+ font-size : 100px ;
30+ }
31+ </ style >
32+
33+ < script >
34+ const hero = document . querySelector ( '.hero' ) ;
35+ const text = hero . querySelector ( 'h1' ) ;
36+ const walk = 100 ;
37+
38+ function shadow ( e ) {
39+ const { offsetWidth : width , offsetHeight : height } = hero ;
40+ let { offsetX : x , offsetY : y } = e ;
41+ if ( this !== e . target ) {
42+ x = x + e . target . offsetLeft ;
43+ y = y + e . target . offsetTop ;
44+ }
45+ const xWalk = Math . round ( ( x / width * walk ) - ( walk / 2 ) ) ;
46+ const yWalk = Math . round ( ( y / height * walk ) - ( walk / 2 ) ) ;
47+ text . style . textShadow = `${ xWalk } px ${ yWalk } px 0 red` ;
48+ }
49+
50+ hero . addEventListener ( 'mousemove' , shadow ) ;
51+ </ script >
52+ </ body >
53+ </ html >
You can’t perform that action at this time.
0 commit comments