-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
109 lines (52 loc) · 1.81 KB
/
main.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
'use strict';
//declare and define all important variable
let body = document.getElementsByTagName('body')[0];
let section = document.querySelector('section');
let p = document.getElementsByTagName('p')[0];
let button = document.getElementsByTagName('button')[0];
let color = [0,1,2,3,4,5,6,7,8,9,'a','b','c','d','e','f'];
let rand;
let even = 1;
//add listener to button
button.addEventListener('click', function() {
if (p.innerText.length >= 6) {
p.innerText = '';
}
//choose random color code
for (let count = 1; count <= 6; count++) {
rand = Math.random() * color.length;
rand = Math.floor(rand);
p.innerText += color[rand];
if (count == 6) {
p.innerText = '#' + p.innerText;
}
}
body.style.backgroundColor = p.innerText;
button.style.backgroundColor = p.innerText;
//add gradient effect the button when clicked
if (even == 1) {
button.style.backgroundImage = 'linear-gradient(to top left, red, yellow, green)';
even++;
} else if (even == 2) {
button.style.backgroundImage = 'linear-gradient(to bottom left, red, yellow, green)';
even++;
} else if (even == 3) {
button.style.backgroundImage = 'linear-gradient(to bottom right, red, yellow, green)';
even++;
} else {
button.style.backgroundImage = 'linear-gradient(to top right, red, yellow, green)';
even = 1;
}
//add box shadow to section
function shadow() {
let pick = p.innerText.slice(1, 7).split('').reverse().join('');
pick = '#' + pick;
section.style.boxShadow = `3px 3px 3px ${pick}, -3px -3px 3px ${pick}, -3px 3px 3px ${pick}, 3px -3px 3px ${pick}`;
}
shadow();
})
// applied copy system
p.addEventListener('click', function() {
navigator.clipboard.writeText(p.innerText);
alert(p.innerText + ' - Copy Successful');
})