-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
47 lines (34 loc) · 1.29 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
var body = document.querySelector('body');
var colorOneInput = document.getElementById('colorOneInput');
var colorTwoInput = document.getElementById('colorTwoInput');
var background = document.getElementById('background');
var copyIcon = document.getElementById('copyIcon');
var tooltip = document.getElementById("tooltip");
function getBackground() {
return `linear-gradient(to right, ${colorOneInput.value}, ${colorTwoInput.value})`
}
function setBackgroundText() {
background.textContent = `${getBackground()};`;
}
function setGradient() {
body.style.background = getBackground();
setBackgroundText();
}
function copyBackground() {
var tempInput = document.createElement('input');
tempInput.value = background.textContent;
document.body.appendChild(tempInput);
tempInput.select();
tempInput.setSelectionRange(0, 99999);
navigator.clipboard.writeText(tempInput.value);
tooltip.innerHTML = 'Background copied';
document.body.removeChild(tempInput);
}
function resetTooltip() {
tooltip.innerHTML = 'Copy to clipboard';
}
setBackgroundText();
colorOneInput.addEventListener('input', setGradient);
colorTwoInput.addEventListener('input', setGradient);
copyIcon.addEventListener('click', copyBackground);
copyIcon.addEventListener('mouseout', resetTooltip);