File tree Expand file tree Collapse file tree 2 files changed +64
-0
lines changed
Expand file tree Collapse file tree 2 files changed +64
-0
lines changed 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+
28+ h1 {
29+ text-shadow : 10px 10px 0 rgba (0 , 0 , 0 , 1 );
30+ font-size : 100px ;
31+ }
32+ </ style >
33+
34+ < script src ="script.js " charset ="utf-8 "> </ script >
35+
36+ </ body >
37+ </ html >
Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+
3+ const hero = document . querySelector ( '.hero' ) ;
4+ const text = hero . querySelector ( 'h1' ) ;
5+ const walk = 100 ; // distance max => max coordinates are going to be -50 et +50 around the element
6+
7+ const { offsetHeight : height , offsetWidth : width } = hero ;
8+
9+ function shadow ( event ) {
10+ let { offsetX : x , offsetY : y } = event ;
11+ //this = hero, but event.target = hero or h1 (children of hero)
12+ if ( this !== event . target ) {
13+ x += event . target . offsetLeft ;
14+ y += event . target . offsetTop ;
15+ }
16+
17+ const xwalk = Math . round ( x / width * walk - walk / 2 ) ;
18+ const ywalk = Math . round ( y / height * walk - walk / 2 ) ;
19+ console . log ( xwalk , ywalk ) ;
20+ text . style . textShadow = `
21+ ${ xwalk } px ${ ywalk } px 0 rgb(87, 140, 32),
22+ ${ xwalk * - 1 } px ${ ywalk * - 1 } px 0 rgb(164, 111, 5)
23+ ` ;
24+ }
25+
26+
27+ hero . addEventListener ( 'mousemove' , shadow ) ;
You can’t perform that action at this time.
0 commit comments