-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
111 lines (102 loc) · 3.2 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Event Object Example</title>
<style>
*{
margin:0;
padding:0;
box-sizing: border-box;
}
/* html{
} */
body{
width:100%;
height:100vh;
background-image:linear-gradient(to right,#5c91e5,#983fc6);
display:flex;
align-items: center;
justify-content: center;
}
section{
margin-top: -5%;
& button{
padding:0.6rem 2rem;
border-radius: 1rem;
margin:7% ;
box-shadow: rgba(0, 0, 0, 0.24) 1px 8px 8px;
margin-bottom: 1.7rem;
}
#myButton{
background-color:#6b9de9;
}
#myButton2{
background-color:#008793;
}
/* input field ke kisi bhi data ke liye "value" use karna padta hai */
& h2{
margin-left:20%;
font-size:1.2rem;
letter-spacing:0.001rem ;
color:#fff;
}
& .copyCode{
margin-top:1.8rem;
margin-left:-2%;
padding:1.5rem;
background-color: transparent;
border-left:solid white;
box-shadow: rgba(0, 0, 0, 0.24) 0px 3px 8px;
}
}
</style>
</head>
<body>
<section>
<div>
<button id="myButton">#5c91e5</button>
<button id="myButton2">#983fc6</button>
</div>
<h2>Copy your code here</h2>
<div class="copyCode">
background-image:linear-gradient(to right,#5c91e5,#983fc6)
</div>
</section>
<script>
let btn1=document.getElementById("myButton");
let btn2=document.getElementById("myButton2")
let copyDiv = document.querySelector(".copyCode");
const hexValues=()=>{
let Values="0123456789abcddef";
let colors="#";
for(let i=0;i<6;i++){
colors=colors + Values[Math.floor(Math.random()*16)];
}
return colors;
}
let rgb1="#5c91e5";
let rgb2="#983fc6";
const handleButton1=()=>{
rgb1=hexValues();
document.body.style.backgroundImage=`linear-gradient(to right,${rgb1},${rgb2} )`;
copyDiv.innerHTML=`background-image:linear-gradient(to right,${rgb1},${rgb2})`;
btn1.innerHTML=`${rgb1}`;
}
const handleButton2=()=>{
rgb2=hexValues();
document.body.style.backgroundImage=`linear-gradient(to right,${rgb1},${rgb2} )`;
copyDiv.innerHTML=`background-image:linear-gradient(to right,${rgb1},${rgb2})`;
btn2.innerHTML=`${rgb2}`;
}
btn1.addEventListener("click",handleButton1);
btn2.addEventListener("click",handleButton2);
copyDiv.addEventListener("click",()=>{
// API Used here
navigator.clipboard.writeText(copyDiv.innerHTML);
alert("Copied");
})
</script>
</body>
</html>