File tree Expand file tree Collapse file tree 3 files changed +39
-0
lines changed
Expand file tree Collapse file tree 3 files changed +39
-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+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
6+ < title > Mouse Chaser</ title >
7+ < link rel ="stylesheet " href ="styles.css ">
8+ </ head >
9+ < body >
10+ < div class ="mover " onmouseover ="moverHandler() " id ="catch ">
11+ < p > Catch me if you can</ p >
12+ </ div >
13+ < script src ="script.js "> </ script >
14+ </ body >
15+ </ html >
Original file line number Diff line number Diff line change 1+ const moverHandler = ( ) => {
2+ let moverEle = document . getElementsByClassName ( "mover" ) [ 0 ] ;
3+
4+ let maxX = window . innerWidth - moverEle . clientWidth ;
5+ let maxY = window . innerHeight - moverEle . clientHeight ;
6+
7+ let randomX = Math . random ( ) * maxX ;
8+ let randomY = Math . random ( ) * maxY ;
9+
10+ randomX = Math . min ( randomX , maxX ) ;
11+ randomY = Math . min ( randomY , maxY ) ;
12+
13+ moverEle . style . transform = `translate(${ randomX } px, ${ randomY } px)` ;
14+ } ;
Original file line number Diff line number Diff line change 1+ .mover {
2+ background-color : lightskyblue;
3+ color : black;
4+ display : inline-block;
5+ padding : 0px 20px ;
6+ margin : 20px ;
7+ font-family : "Arial" ;
8+ font-size : large;
9+ position : relative;
10+ }
You can’t perform that action at this time.
0 commit comments