1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+ < head >
4+ < meta charset ="UTF-8 ">
5+ < meta http-equiv ="X-UA-Compatible " content ="IE=edge ">
6+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
7+ < link rel ="shortcut icon " href ="img/logo.png " type ="image/x-icon ">
8+ < link rel ="stylesheet " href ="css/style.css ">
9+ < script src ="js/script.js "> </ script >
10+ < title > Gradient Generator</ title >
11+
12+ <!-- Bootstrap fontawesome icons -->
13+ < link href ="
https://cdn.jsdelivr.net/npm/[email protected] /dist/css/bootstrap.min.css "
rel ="
stylesheet "
integrity ="
sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC "
crossorigin ="
anonymous "
> 14+ < script src ="
https://cdn.jsdelivr.net/npm/[email protected] /dist/js/bootstrap.bundle.min.js "
integrity ="
sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM "
crossorigin ="
anonymous "
> </ script > 15+ < script src ="https://kit.fontawesome.com/9525e0b59f.js " crossorigin ="anonymous "> </ script >
16+ </ head >
17+ < body id ="body ">
18+ < div class ="centerContent ">
19+ < h1 > Random Gradient Generator</ h1 >
20+ < p class ="text-secondary mb-1 "> By clicking above button a random gradient will be generated for you</ p >
21+ < button class ="btn btn-danger rounded-pill px-5 mt-2 " onClick ="genRandomHex() "> AUTO GENERATE</ button >
22+
23+ < div class ="copy-link ">
24+ < input type ="text " class ="copy-link-input " readonly />
25+ < button type ="button " class ="copy-link-button ">
26+ < span class ="fa fa-clipboard "> </ span >
27+ </ button >
28+ </ div >
29+
30+ < div class ="manuallGen ">
31+ < p class ="text-secondary mb-1 "> Generate gradient by giving two color values</ p >
32+ < input class ="colorPicker " value ="#18d26d " type ="color " id ="color1 " name ="color1 ">
33+ < input class ="colorPicker " value ="#22a7f2 " type ="color " id ="color2 " name ="color2 "> < br >
34+ < button class ="btn btn-primary rounded-pill px-5 mt-2 " onClick ="genCustomHex() "> Manually Generate</ button >
35+ </ div >
36+
37+
38+ </ div >
39+ < p class ='credits '> Made By < b > Yasir Nawaz</ b > with < span class ='fa fa-heart heartEmoji '> </ span > </ p >
40+
41+ < script >
42+ const hexNum = [
43+ '1' ,
44+ '2' ,
45+ '3' ,
46+ '4' ,
47+ '5' ,
48+ '6' ,
49+ '7' ,
50+ '8' ,
51+ '9' ,
52+ 'a' ,
53+ 'b' ,
54+ 'c' ,
55+ 'd' ,
56+ 'e' ,
57+ 'f'
58+ ] ;
59+
60+ function genRandomHex ( ) {
61+ let hex1 = '' ;
62+ let hex2 = '' ;
63+
64+ for ( let i = 0 ; i < 6 ; i ++ ) {
65+ hex1 += hexNum [ Math . floor ( Math . random ( ) * hexNum . length ) ] ;
66+ hex2 += hexNum [ Math . floor ( Math . random ( ) * hexNum . length ) ] ;
67+ }
68+
69+ const gradient = `linear-gradient(45deg, #${ hex1 } , #${ hex2 } )` ;
70+
71+ document . getElementById ( 'body' ) . style . background = gradient ;
72+ document . getElementById ( 'body' ) . classList . add ( 'bg-transition' ) ;
73+ document . querySelector ( ".copy-link-input" ) . value = `background: ${ gradient } ` ;
74+ }
75+
76+
77+ document . querySelectorAll ( ".copy-link" ) . forEach ( ( copyLinkParent ) => {
78+ const inputField = copyLinkParent . querySelector ( ".copy-link-input" ) ;
79+ const copyButton = copyLinkParent . querySelector ( ".copy-link-button" ) ;
80+ const text = inputField . value ;
81+
82+ inputField . addEventListener ( "focus" , ( ) => inputField . select ( ) ) ;
83+
84+ copyButton . addEventListener ( "click" , ( ) => {
85+ inputField . select ( ) ;
86+ navigator . clipboard . writeText ( inputField . value ) ;
87+ inputField . value = "Copied!" ;
88+ setTimeout ( ( ) => {
89+ inputField . value = `background: ${ gradient } ` ;
90+ } , 2000 ) ;
91+ } ) ;
92+
93+
94+
95+ } ) ;
96+
97+
98+ function genCustomHex ( ) {
99+ const hex1 = document . getElementById ( 'color1' ) . value . substring ( 1 ) ;
100+ const hex2 = document . getElementById ( 'color2' ) . value . substring ( 1 ) ;
101+
102+ const gradient = `linear-gradient(45deg, #${ hex1 } , #${ hex2 } )` ;
103+
104+ document . getElementById ( 'body' ) . style . background = gradient ;
105+ document . getElementById ( 'body' ) . classList . add ( 'bg-transition' ) ;
106+ document . querySelector ( ".copy-link-input" ) . value = `background: ${ gradient } ` ;
107+ }
108+
109+ </ script >
110+
111+ </ body >
112+ </ html >
0 commit comments