From 5eca4a190533249c206b3ac56e9456f48efc519c Mon Sep 17 00:00:00 2001 From: Meet Shah <128205241+Meetpidev@users.noreply.github.com> Date: Tue, 8 Oct 2024 14:28:59 +0530 Subject: [PATCH] Random_Gradient_Color You can get random gradient color by pressing space. --- Random_Gradient_Color/README.md | 1 + Random_Gradient_Color/index.html | 24 +++++++++++++ Random_Gradient_Color/script.js | 36 +++++++++++++++++++ Random_Gradient_Color/style.css | 59 ++++++++++++++++++++++++++++++++ 4 files changed, 120 insertions(+) create mode 100644 Random_Gradient_Color/README.md create mode 100644 Random_Gradient_Color/index.html create mode 100644 Random_Gradient_Color/script.js create mode 100644 Random_Gradient_Color/style.css diff --git a/Random_Gradient_Color/README.md b/Random_Gradient_Color/README.md new file mode 100644 index 00000000..a0389c8c --- /dev/null +++ b/Random_Gradient_Color/README.md @@ -0,0 +1 @@ +In this project youcan get random gradient colors by pressing space. \ No newline at end of file diff --git a/Random_Gradient_Color/index.html b/Random_Gradient_Color/index.html new file mode 100644 index 00000000..a2956b2c --- /dev/null +++ b/Random_Gradient_Color/index.html @@ -0,0 +1,24 @@ + + + + + + Random Linear Gradient Generator + + + +
+

Press SPACE

+

+ color-1 + + color-2 +

+ +
+

CSS Background Linear Gradient

+
+
+ + + \ No newline at end of file diff --git a/Random_Gradient_Color/script.js b/Random_Gradient_Color/script.js new file mode 100644 index 00000000..cf475cd5 --- /dev/null +++ b/Random_Gradient_Color/script.js @@ -0,0 +1,36 @@ +//DOM Elements +const color1Elem = document.getElementById('color-1'); +const color2Elem = document.getElementById('color-2'); +const codeElem = document.querySelector('.code'); +const btn = document.querySelector('.btn'); +const infoElem = document.querySelector('.info'); + +//Generate HEX +function getHEX(){ + let randomHex = Math.random().toString(16).substr(-6); + let hexColor = `#${randomHex}`; + return hexColor; +} + +//Update the UI +function updateUI(){ + infoElem.remove(); + + color1Elem.innerText = getHEX(); + color2Elem.innerText = getHEX(); + + color1Elem.style.background = color1Elem.innerText; + color2Elem.style.background = color2Elem.innerText; + + codeElem.innerText = `background: linear-gradient(90deg, ${color1Elem.innerText}, ${color2Elem.innerText});`; + document.body.style.background = `linear-gradient(90deg, ${color1Elem.innerText}, ${color2Elem.innerText})`; +} + +//when user clicks SPACE or the arrow, then UpdateUI + +window.addEventListener('keydown', event => { + if(event.code === 'Space') + updateUI(); +}); + +btn.addEventListener('click', updateUI); \ No newline at end of file diff --git a/Random_Gradient_Color/style.css b/Random_Gradient_Color/style.css new file mode 100644 index 00000000..dca3c00d --- /dev/null +++ b/Random_Gradient_Color/style.css @@ -0,0 +1,59 @@ +* { + margin: 0; + padding: 0; + box-sizing: border-box; +} +*::before, +*::after { + box-sizing: border-box; +} +html, +body { + font-size: 10px; + font-family: 'lato', Arial, Helvetica, sans-serif; +} +body { + min-height: 100vh; + display: flex; + justify-content: center; + align-items: flex-end; +} +.container { + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + margin-bottom: 2rem; +} +.colors { + font-size: 2.5rem; + margin-bottom: 5rem; +} +.color { + background: black; + color: white; + padding: 0.7rem 1rem; + border-radius: 5rem; + display: inline-block; + width: 12rem; + text-align: center; +} +.btn { + border: none; + cursor: pointer; + background: transparent; + font-size: 3rem; +} +.output { + font-size: 1.7rem; + background: black; + color: white; + border-radius: 0.5rem; + padding: 3rem; + width: 50rem; + text-align: center; +} +.info { + font-size: 3rem; + margin-bottom: 10rem; +} \ No newline at end of file