-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
52 lines (44 loc) · 1.66 KB
/
script.js
File metadata and controls
52 lines (44 loc) · 1.66 KB
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
const css = document.querySelector('h3');
const color1 = document.querySelector('.color1');
const color2 = document.querySelector('.color2');
const body = document.getElementById('gradient');
const auto = document.getElementById('auto');
const reset = document.getElementById('reset');
const btn = document.getElementById('copy');
const colorValue = document.getElementById('myInput');
const setGradient = function () {
body.style.background = "Linear-gradient(to right," + color1.value
+ "," + color2.value + ")";
css.textContent = body.style.background + ";";
}
function setRandomBG() {
let randomColor1 = Math.floor(Math.random() * 16777215).toString(16);
let randomColor2 = Math.floor(Math.random() * 16777215).toString(16);
let randColor1 = "#" + randomColor1.padStart(6, 0);
let randColor2 = "#" + randomColor2.padStart(6, 0);
console.log(randColor1, randColor2);
const hexColorValue = `${randColor1} ${randColor2}`;
colorValue.value = hexColorValue;
color1.value = randColor1;
color2.value = randColor2;
setGradient();
}
function colorReset() {
body.style.background = "linear-gradient(to right, red , yellow)";
css.textContent = '';
colorValue.value = `Copy color value`;
}
btn.addEventListener('click', async function () {
try {
await navigator.clipboard.writeText(`${colorValue.value}`);
var tooltip = document.getElementById("myTooltip");
tooltip.innerHTML = `Copied: ${colorValue.value} value to the clipboard!!`;
}
catch {
console.error('Text cant be copied');
}
});
color1.addEventListener('input', setGradient);
color2.addEventListener('input', setGradient);
auto.addEventListener('click', setRandomBG);
reset.addEventListener('click', colorReset);