File tree Expand file tree Collapse file tree 2 files changed +65
-40
lines changed
Expand file tree Collapse file tree 2 files changed +65
-40
lines changed Load Diff This file was deleted.
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+ body {
20+ margin : 0 ;
21+ }
22+
23+ .hero {
24+ min-height : 100vh ;
25+ display : flex;
26+ justify-content : center;
27+ align-items : center;
28+ color : black;
29+ }
30+
31+ h1 {
32+ text-shadow : 10px 10px 0 rgba (0 , 0 , 0 , 1 );
33+ font-size : 100px ;
34+ }
35+ </ style >
36+
37+ < script >
38+
39+ const hero = document . querySelector ( ".hero" ) ;
40+ const text = hero . querySelector ( "h1" ) ;
41+ const walk = 100 ;
42+
43+ function onMouseMove ( e ) {
44+ const { offsetWidth : width , offsetHeight : height } = hero ;
45+ let { offsetX : x , offsetY : y } = e ;
46+
47+ if ( this != e . target ) {
48+ x += e . target . offsetLeft ;
49+ y += e . target . offsetTop ;
50+ }
51+
52+ const xWalk = ( x / width * walk ) - ( walk / 2 ) ;
53+ const yWalk = ( y / height * walk ) - ( walk / 2 ) ;
54+
55+ text . style . textShadow = `${ xWalk } px ${ yWalk } px 0 red` ;
56+
57+
58+ }
59+
60+ hero . addEventListener ( 'mousemove' , onMouseMove ) ;
61+
62+
63+ </ script >
64+ </ body >
65+ </ html >
You can’t perform that action at this time.
0 commit comments