-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
36 lines (30 loc) · 1.11 KB
/
script.js
File metadata and controls
36 lines (30 loc) · 1.11 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
let body = document.querySelector('.body');
let color1 = document.querySelector('.color1');
let color2 = document.querySelector('.color2');
let displayValue1 = document.querySelectorAll('.color1Value');
let displayValue2 = document.querySelectorAll('.color2Value');
const gradientCode = document.querySelector('.gradient-code');
const createSnippet = (colorCode1, colorCode2) => {
displayValue1.forEach((element) => {
element.textContent = colorCode1;
});
displayValue2.forEach((element) => {
element.textContent = colorCode2;
console.log(element.textContent);
});
};
const updateGradient = () => {
body.style.background = `linear-gradient(to right, ${color1.value}, ${color2.value})`;
createSnippet(color1.value, color2.value);
};
const generateRandomGradient = () => {
color1.value = '#' + Math.floor(Math.random() * 16777215).toString(16);
color2.value = '#' + Math.floor(Math.random() * 16777215).toString(16);
updateGradient();
};
gradientCode.addEventListener('click', () => {
navigator.clipboard.writeText(gradientCode.textContent).then(() => {
window.alert('Copied to clipboard');
});
});
updateGradient();