-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
28 lines (26 loc) · 953 Bytes
/
script.js
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
const body = document.querySelector("body");
const copyButton = document.querySelector(".copy-button");
const placeholderDiv = document.querySelector(".placeholder-div");
const generateButton = document.querySelector(".generate-button");
let gradient = "";
function generateRandomGradient() {
return `linear-gradient(to right, rgb(${Math.floor(
Math.random() * 255
)},${Math.floor(Math.random() * 255)},${Math.floor(Math.random() * 255)}),
rgb(${Math.floor(Math.random() * 255)},${Math.floor(
Math.random() * 255
)},${Math.floor(Math.random() * 255)}))`;
}
function copyToClipboard() {
navigator.clipboard.writeText(gradient);
alert("Copied!");
}
window.onload = function () {
gradient = generateRandomGradient();
body.style.backgroundImage = gradient;
};
generateButton.addEventListener("click", function () {
gradient = generateRandomGradient();
body.style.backgroundImage = gradient;
console.log(gradient);
});