File tree Expand file tree Collapse file tree 3 files changed +74
-0
lines changed Expand file tree Collapse file tree 3 files changed +74
-0
lines changed Original file line number Diff line number Diff line change 1+ let color1 = document . querySelector ( ".c1" ) ;
2+ let color2 = document . querySelector ( ".c2" ) ;
3+ let gradientCont = document . querySelector ( "#gradient-cont" ) ;
4+ let btn = document . querySelector ( ".randomColorBtn" ) ;
5+
6+ function makeColor ( ) {
7+ let randomColor = Math . floor ( Math . random ( ) * 16777215 ) . toString ( 16 ) ;
8+ return randomColor ;
9+ }
10+
11+ function generateGradient ( ) {
12+ color1 . value = "#" + makeColor ( ) ;
13+ color2 . value = "#" + makeColor ( ) ;
14+ gradientCont . style . background = `linear-gradient(${ color1 . value } , ${ color2 . value } )` ;
15+ }
16+
17+ function setGradient ( ) {
18+ gradientCont . style . background = `linear-gradient(${ color1 . value } , ${ color2 . value } )` ;
19+ }
20+
21+ document . body . addEventListener ( "load" , generateGradient ( ) ) ;
22+ color1 . addEventListener ( "input" , setGradient ) ;
23+ color2 . addEventListener ( "input" , setGradient ) ;
24+ btn . addEventListener ( "click" , generateGradient ) ;
Original file line number Diff line number Diff line change 1+ < html lang ="en ">
2+ < head >
3+ < meta charset ="UTF-8 " />
4+ < meta http-equiv ="X-UA-Compatible " content ="IE=edge " />
5+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 " />
6+ < title > Gradient Generator</ title >
7+ < link rel ="stylesheet " href ="style.css " />
8+ </ head >
9+ < body >
10+ < section >
11+ < div class ="cont " id ="gradient-cont "> </ div >
12+ < div class ="cont ">
13+ < input type ="color " class ="colors c1 " />
14+ < input type ="color " class ="colors c2 " />
15+ < br />
16+ < button class ="randomColorBtn "> Random</ button >
17+ </ div >
18+ </ section >
19+
20+ < script src ="app.js "> </ script >
21+ </ body >
22+ </ html >
Original file line number Diff line number Diff line change 1+ body {
2+ display : flex;
3+ justify-content : center;
4+ }
5+
6+ section {
7+ margin : 10vh 10vw ;
8+ display : flex;
9+ flex-direction : row;
10+ }
11+
12+ .cont {
13+ width : 40vw ;
14+ }
15+
16+ .colors {
17+ outline : none;
18+ border : none;
19+ width : 100px ;
20+ height : 100px ;
21+ }
22+
23+ .randomColorBtn {
24+ margin-top : 20px ;
25+ padding : 10px 20px ;
26+ margin-left : 3rem ;
27+ cursor : pointer;
28+ }
You can’t perform that action at this time.
0 commit comments