-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
40 lines (34 loc) · 1.09 KB
/
script.js
File metadata and controls
40 lines (34 loc) · 1.09 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
var col1 = document.querySelector('#col1');
var col2 = document.querySelector('#col2');
var text = document.querySelector('#text');
var body = document.querySelector('body');
var alertdone = document.querySelector('.alertdone');
col1.addEventListener('input', setGradient);
col2.addEventListener('input', setGradient);
function setGradient() {
alertdone.classList.add('done');
body.style.background = 'linear-gradient(to right,' + col1.value + ',' + col2.value + ')';
text.value = body.style.background + ';';
}
// w3
function myFunction() {
/* Get the text field */
text.toggleAttribute('disabled');
var copyText = text;
/* Select the text field */
copyText.select();
/*For mobile devices*/
copyText.setSelectionRange(0, 99999);
/* Copy the text inside the text field */
document.execCommand('copy');
text.toggleAttribute('disabled');
alertdone.classList.toggle('done');
}
function getRandomColor() {
return '#' + Math.floor(Math.random() * 16777216).toString(16);
}
function setRandomColor() {
col1.value = getRandomColor();
col2.value = getRandomColor();
setGradient();
}