File tree Expand file tree Collapse file tree 1 file changed +77
-0
lines changed
Expand file tree Collapse file tree 1 file changed +77
-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 > Day 80/100</ title >
7+ </ head >
8+ < body >
9+ < main >
10+ < div class ="square-container " id ="square-container ">
11+ < div class ="square " id ="square "> </ div >
12+ </ div >
13+ </ main >
14+
15+ < style >
16+ body {
17+ background-color : # 000 ;
18+ overflow : hidden;
19+ display : flex;
20+ justify-content : center;
21+ align-items : center;
22+ width : 100vw ;
23+ height : 100vh ;
24+ margin : 0 ;
25+ }
26+
27+ .square-container {
28+ position : relative;
29+ width : 100vw ;
30+ height : 100px ;
31+ background-color : rgba (20 , 20 , 20 , 1 );
32+ }
33+
34+ .square {
35+ position : absolute;
36+ top : 0 ;
37+ left : 0 ;
38+ width : 100px ;
39+ height : 100px ;
40+ background-color : # fff ;
41+ transition : all 0.5s ease-in-out;
42+ }
43+ </ style >
44+
45+ < script >
46+ const squareContainer = document . getElementById ( "square-container" ) ;
47+ const square = document . getElementById ( "square" ) ;
48+
49+ let animating = false ;
50+
51+ squareContainer . addEventListener ( "click" , ( e ) => {
52+ const x = e . clientX ;
53+ if ( animating ) return ;
54+ animating = true ;
55+ let left = Math . max (
56+ 0 ,
57+ Math . min (
58+ x - square . offsetWidth / 2 ,
59+ squareContainer . offsetWidth - square . offsetWidth
60+ )
61+ ) ;
62+ let angle ;
63+ if ( square . style . rotate ) {
64+ angle = parseFloat ( square . style . rotate . split ( "deg" ) [ 0 ] ) ;
65+ } else {
66+ angle = 0 ;
67+ }
68+
69+ square . style . left = `${ left } px` ;
70+ square . style . rotate = `${ angle + 180 } deg` ;
71+ setTimeout ( ( ) => {
72+ animating = false ;
73+ } , 500 ) ;
74+ } ) ;
75+ </ script >
76+ </ body >
77+ </ html >
You can’t perform that action at this time.
0 commit comments