-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
92 lines (76 loc) · 2.55 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
const body = document.querySelector("body");
const input1 = document.getElementById("colour1");
const input2 = document.getElementById("colour2");
const copy = document.getElementById("copy");
let css = document.getElementById("css");
let tooltip = document.querySelector(".tooltip");
let tooltiptext = document.querySelector(".tooltiptext");
const random = document.querySelector(".randomise");
//background-colour-change-on-input
function bgColChange ()
{
body.style.background=`linear-gradient(to right, ${input1.value}, ${input2.value})`;
css.innerText=(`CSS: linear-gradient(to right, ${input1.value}, ${input2.value})`);
console.log("input1", input1.value);
}
input1.addEventListener("input", bgColChange);
input2.addEventListener("input", bgColChange);
input1.addEventListener("change", bgColChange);
input2.addEventListener("change", bgColChange);
//Copy-CSS
//focusin , focusout
//click used instead of focus(works the same for mouse) to avoid tab key event meddling
copy.addEventListener("click", ()=>{
let select =css.innerHTML;
navigator.clipboard.writeText(select.slice(5)); //copy content inside select
copy.children[0].setAttribute("src", "copy-fill.svg"); //change copy icon to copied
tooltiptext.innerHTML = "Copied!";
})
copy.addEventListener("focusout", ()=>{
copy.children[0].setAttribute("src", "copy.svg"); //change copied icon to copy
tooltiptext.innerHTML = "Copy CSS!";
});
copy.addEventListener("mouseenter", ()=>{
tooltip.style.visibility = "visible";
})
copy.addEventListener("mouseleave", ()=>{
tooltip.style.visibility = "hidden";
})
//random colour generate
function toHex(n){
//decimal to hex
switch(n){
case 10: return 'a';
case 11: return 'b';
case 12: return 'c';
case 13: return 'd';
case 14: return 'e';
case 15: return 'f';
default: return n;
}
}
function randomise()
{
//generate random hex code
let s1="#", s2="#";
for(let i=0; i<6; i++)
{
//generate random number from 0 to 15
let n = Math.floor(Math.random()*16);
s1 += toHex(n);
}
for(let i=0; i<6; i++)
{
//generate random number from 0 to 15
let n = Math.floor(Math.random()*16);
s2 += toHex(n);
}
input1.value=s1;
input2.value=s2;
bgColChange();
}
random.addEventListener("click", randomise);
//add Randomise button
//add dropdown for 2 or 3 gradients select
//add copy css button --done, works
//customise color-stop's position (the point where transition to 2nd color begins)