Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Color Changer #1160

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added 112- Color Changer/img.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions 112- Color Changer/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!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>Document</title>
<link rel="stylesheet" href="./style.css"></link>
</head>
<body>
<div class="name">
<h1 id="str">
Random Color Generator
</h1>
</div>
<div class="main">

<div class="container">
<h2 id="color-code">#fff</h2>
<button id="btn">Click Me</button>
</div>
</div>

<script src="./script.js"></script>
</body>
</html>
19 changes: 19 additions & 0 deletions 112- Color Changer/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const getcolor=()=>{
const randomNUM=Math.floor(Math.random()*16777215);

//converting random number to hexadecimal
const randomCode="#"+randomNUM.toString(16);

//accessing background color
document.body.style.backgroundColor=randomCode;

//changing color hexadecimal name
document.getElementById('color-code').innerHTML=randomCode;

//used to copy to the clipborad
navigator.clipboard.writeText(randomCode);

}

document.getElementById("btn").addEventListener("click", getcolor);
getcolor();
55 changes: 55 additions & 0 deletions 112- Color Changer/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
*{
padding: 0;
margin: 0;
box-sizing: border-box;
font-family: 'Roboto',sans-serif;
}

body{
background-color: black;
transition: 0.5s;
}
.main{
width: 100%;
height: 80vh;
display: flex;
justify-content: center;
align-items: center;
}

.container{
width: 30rem;
/* height: 100vh; */
padding: 10px;
border-radius: 10px;
background-color: white;
text-align: center;
}

button{
margin-top: 5px;
width: 100%;
background-color: black;
color: aliceblue;
border: none;
border-radius: 5px;
display: block;
font-size: 35px;
}
button:hover{
cursor: pointer;
}

.name{
justify-content: center;
text-align: center;
display: flex;
padding-top: 100px;
}

#str{
font-size:xx-large;
font-weight: bolder;
font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;
font-style:normal;
}
12 changes: 11 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1090,7 +1090,7 @@ <h4>Maths addition</h4>
</div>

<div class="item">
<img src="30DaysOfJavaScript/assets/109.png" alt="Number Facts">
<img src="./112- Color Changer/img.png" alt="Color Changer">
<h4>Number Facts</h4>
<a target="_blank"
href="https://github.com/swapnilsparsh/30DaysOfJavaScript/tree/master/109%20-%20Number%20Facts">
Expand Down Expand Up @@ -1119,6 +1119,16 @@ <h4>Luminosity Particle Js</h4>
</a>
</div>

<div class="item">
<img src="30DaysOfJavaScript/assets/07.png" alt="Dynamic Form Field" />
<h4>Color Changer</h4>
<a target="_blank"
href="https://github.com/swapnilsparsh/30DaysOfJavaScript/tree/master/07%20-%20Dynamic%20Form%20Field">
<i class="fa-brands fa-square-github"></i>
<a target="_blank" href="112- Color Changer/index.html"><i class="fa-solid fa-link"></i> </a>
</a>
</div>

</div>
<!-- Main Section End -->

Expand Down