-
Notifications
You must be signed in to change notification settings - Fork 8
/
randomhex.html.html
67 lines (61 loc) · 2.39 KB
/
randomhex.html.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Random Hex Generator</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
</head>
<style>
h3{
display: inline-block;
margin-top: 30px;
padding: 15px;
box-shadow: 0px 3px 8px rgb(207, 206, 206);
border-radius: 5px;
}
</style>
<body>
<div class="container">
<div class="row">
<!--title-->
<div class="col-12 col-md-12 col-lg-12">
<h2 class ="text-center" style="padding: 20px;margin-top: 30px;">Random Background Hex Color Generator</h2>
</div>
<!--Hex Code Card-->
<div class="col-12 col-md-12 col-lg-12 mx-auto text-center">
<h3 class= "text-center">Hex Color : <span id="hex">#ff5c5c</span></h3>
</div>
<!--Generate Button-->
<div class="col-12 col-md-12 col-lg-12" text-center>
<button class="btn btn-outline-light">Generate Color</button>
</div>
</div>
</div>
</div>
</div>
</body>
<!-- JS -->
<script>
const body= document.querySelector("body");
const generate= document.querySelector(".generate");
const hex= document.querySelector("#hex");
const input= document.querySelector("#input");
generate.addEventListener("click", () =>{
const hexcode = [0,1,2,3,4,5,6,7,8,9,"A","B","C","D","E","F"];
var hex_key = "#";
for(let i = 0 ; i < 6 ;i++){
let hex_value = Math.floor (Math.random() * hexcode.length);
hex_key= hex_key + hexcode [hex_value];
}
body.style.backgroundColor= hex_key;
hex.innerHTML= hex_key .toLowerCase();
input.value= hex_key.toLowerCase();
})
input.addEventListener('keyup', ()=> {
body.style.backgroundColor = input.value.toLowerCase();
hex.innerHTML = input.value.toLowerCase();
})
</script>
</html>