-
Notifications
You must be signed in to change notification settings - Fork 12
/
script.js
64 lines (54 loc) · 1.6 KB
/
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const h3 = document.querySelector('h3');
const color1 = document.querySelector('.color1');
const color2 = document.querySelector('.color2');
const body = document.querySelector('#gradient');
const random = document.querySelector('.generate-btn');
setGradient = () => {
body.style.background = _linearGradient();
random.style.background = _linearGradient();
h3.textContent = `${body.style.background}`;
};
_linearGradient = () => {
return (
'linear-gradient(to right,' +
color1.value +
', ' +
color2.value +
' )'
);
};
setGradient();
color1.addEventListener('input', setGradient);
color2.addEventListener('input', setGradient);
randomColor = () => {
let letters = '0123456789ABCDEF';
let color = '#';
for (let i = 0; i < 6; i++) {
color += letters[Math.floor(Math.random() * 16)];
}
return color;
};
random.addEventListener('click', () => {
color1.value = randomColor();
color2.value = randomColor();
setGradient();
});
const copyToClipboard = () => {
const el = document.createElement('textarea');
el.value = document.getElementById('gradient-value').innerText;
document.body.appendChild(el);
el.select();
document.execCommand('copy');
document.body.removeChild(el);
showNotification();
};
const showNotification = () => {
const timeInterval = 3000; // 3 seconds
const notificationWrapper = document.getElementById('notification');
notificationWrapper.style.top = "20px";
notificationWrapper.style.right = `calc(100vh - ${notificationWrapper.offsetWidth/2}px)`
// Hide notification after specified time interval
setTimeout(()=>{
notificationWrapper.style.top = '-70px';
}, timeInterval)
}