Skip to content

50Projects-HTML-CSS-JavaScript : Gradient background generator #23

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

Merged
merged 5 commits into from
Jul 22, 2024
Merged
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
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,17 @@ In order to run this project you need:
</details>
</li>

<li>
<details>
<summary>Gradient Background Generator</summary>
<p>The Gradient Background Generator is a user-friendly tool built using HTML, CSS, and JavaScript. This project allows users to create beautiful gradient backgrounds effortlessly. Users can select two colors to generate a gradient background and see the corresponding CSS code, which they can easily copy and use in their own projects. The tool is designed to be beginner-friendly, making it an excellent project for those new to web development.</p>
<ul>
<li><a href="https://tajulafreen.github.io/50Projects-HTML-CSS-JavaScript/Source-Code/GradientBackgroundGenerator/">Live Demo</a></li>
<li><a href="https://github.com/tajulafreen/50Projects-HTML-CSS-JavaScript/tree/main/Source-Code/GradientBackgroundGenerator">Source</a></li>
</ul>
</details>
</li>

</ol>

<p align="right">(<a href="#readme-top">back to top</a>)</p>
Expand Down
38 changes: 38 additions & 0 deletions Source-Code/GradientBackgroundGenerator/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Gradient Background Generator</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body id="gradient">
<h1>Background Generator</h1>
<label for="color1">Choose Color 1:</label>
<input
class="color1"
type="color"
id="color1"
name="color1"
value="#ff0000"
/>
<label for="color2">Choose Color 2:</label>
<input
class="color2"
type="color"
id="color2"
name="color2"
value="#ffff00"
/>
<h2>Current CSS Background</h2>
<div id="css-container">
<h3 id="css-background"></h3>
<button id="copy-btn">
<span class="transition"></span>
<span class="gradient"></span>
Copy
</button>
</div>
<script src="script.js"></script>
</body>
</html>
33 changes: 33 additions & 0 deletions Source-Code/GradientBackgroundGenerator/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
document.addEventListener('DOMContentLoaded', () => {
const gradient = document.getElementById('gradient');
const color1 = document.querySelector('.color1');
const color2 = document.querySelector('.color2');
const cssBackground = document.getElementById('css-background');
const copyBtn = document.getElementById('copy-btn');

const updateBackground = () => {
const color1Value = color1.value;
const color2Value = color2.value;
const background = `linear-gradient(to right, ${color1Value}, ${color2Value})`;

gradient.style.background = background;
cssBackground.textContent = `background: ${background};`;
};

const copyToClipboard = () => {
const textToCopy = cssBackground.textContent;
navigator.clipboard.writeText(textToCopy).then(
() => {
alert('CSS background value copied to clipboard!');
},
(err) => {
console.error('Failed to copy: ', err);
},
);
};
color1.addEventListener('input', updateBackground);
color2.addEventListener('input', updateBackground);
copyBtn.addEventListener('click', copyToClipboard);
// Initialize background on page load
updateBackground();
});
54 changes: 54 additions & 0 deletions Source-Code/GradientBackgroundGenerator/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
body {
margin: 0;
padding: 0;
font-family: Arial, sans-serif;
text-align: center;
background: linear-gradient(to right, #f00, #ff0);
transition: 0.5s ease;
}

h1 {
margin-top: 20px;
}

input {
margin: 10px;
border: none;
height: 40px;
width: 100px;
}

h2,
h3 {
margin: 20px;
}

button {
width: 250px;
height: 40px;
background: #eeeff1;
color: rgb(16, 16, 16);
border: none;
border-radius: 0.6em;
cursor: pointer;
font-size: large;
font-weight: 500;
margin-top: 1rem;
transition: 0.5s, color 0.5s, transform 0.5s;
}

button:hover {
background: #8ce0ea;
color: #eeeff1;
transform: scale(1.1);
}

@keyframes button-press {
0% { transform: scale(1); }
50% { transform: scale(0.9); }
100% { transform: scale(1); }
}

button:active {
animation: button-press 0.2s;
}
Loading