-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
249 lines (144 loc) · 6.47 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
// color values for both sections inputs //
const sec1_InputLeft = document.querySelector(".color-1");
const sec1_InputRight = document.querySelector(".color-2");
const sec2_InputLeft = document.querySelector(".color-3");
const sec2_InputRight = document.querySelector(".color-4");
// sections backgrounds //
const sectionOne = document.querySelector(".first-section");
const sectionTwo = document.querySelector(".section-two");
// sections H3`s and P //
const sectionOneH3 = document.querySelector(".first-sec-h3");
const sectionTwoH3 = document.querySelector(".second-sec-h3");
const sectionOneP = sectionOne.querySelector("p");
const sectionTwoP = sectionTwo.querySelector("p");
// sections buttons //
const copyBtn1 = document.querySelector(".copybtn-1");
const copyBtn2 = document.querySelector(".copybtn-2");
const sec1_reverseBtn = document.querySelector(".reverse-btn");
const sec2_reverseBtn = document.querySelector(".reverse-btn-2");
// changing the background for first section //
function changeColorsToRight() {
const colorInputLeft = sec1_InputLeft.value;
const colorInputRight = sec1_InputRight.value;
const currentBackground = window.getComputedStyle(sectionOne).background;
if(currentBackground.includes("to right")) {
sectionOne.style.background =
`linear-gradient(to right,
${colorInputLeft}, ${colorInputRight})`;
sectionOneH3.textContent =
`background: linear-gradient(to right, ${colorInputLeft}, ${colorInputRight});`
} else if(currentBackground.includes("to left")) {
sectionOne.style.background =
`linear-gradient(to left,
${colorInputRight}, ${colorInputLeft})`;
sectionOneH3.textContent =
`background: linear-gradient(to left, ${colorInputRight}, ${colorInputLeft});`
}
}
// changing the background for second section //
function changeColorsToBottom() {
const colorInputTop = sec2_InputLeft.value;
const colorInputBottom = sec2_InputRight.value;
const currentBackground = window.getComputedStyle(sectionTwo).background;
if(currentBackground.includes("to top")) {
sectionTwo.style.background =
`linear-gradient(to top,
${colorInputBottom}, ${colorInputTop})`;
sectionTwoH3.textContent =
`background: linear-gradient(to top, ${colorInputBottom}, ${colorInputTop});`
} else if (!currentBackground.includes("to top")) {
sectionTwo.style.background =
`linear-gradient(to bottom,
${colorInputTop}, ${colorInputBottom})`;
sectionTwoH3.textContent =
`background: linear-gradient(to bottom, ${colorInputTop}, ${colorInputBottom});`
}
}
// copying text for section one //
function copyText() {
const textToCopy = sectionOneH3.textContent;
navigator.clipboard.writeText(textToCopy).then(
popUp
).catch(err => {
console.error(err);
});
}
// copying text for section two //
function copyTextTwo() {
const textToCopy2 = sectionTwoH3.textContent;
navigator.clipboard.writeText(textToCopy2).then(
popUpTwo
).catch(err => {
console.error(err);
});
}
// when copied popUp will make the check icon pop up //
function popUp() {
const checkIconOne = document.querySelector("#sec-one-i");
checkIconOne.style.visibility = "visible";
checkIconOne.classList.toggle("hidden");
checkIconOne.classList.toggle("popup");
}
function popUpTwo() {
const checkIconTwo = document.querySelector("#sec-two-i");
checkIconTwo.style.visibility = "visible";
checkIconTwo.classList.toggle("hidden");
checkIconTwo.classList.toggle("popup");
}
function reverseColors() {
const currentBackground = window.getComputedStyle(sectionOne).background;
let colorInputLeft = sec1_InputLeft.value;
let colorInputRight = sec1_InputRight.value;
if(currentBackground.includes("to right")) {
let reversedBackground = currentBackground.replace("to right", "to left");
sectionOne.style.background = reversedBackground;
sec1_InputLeft.value = colorInputRight;
sec1_InputRight.value = colorInputLeft;
sectionOneH3.textContent = `background: linear-gradient(to left, ${colorInputRight}, ${colorInputLeft});`;
sectionOneP.textContent = "to left";
} else if (currentBackground.includes("to left")) {
reversedBackground = currentBackground.replace("to left" , "to right");
sectionOne.style.background = reversedBackground;
sec1_InputRight.value = colorInputLeft;
sec1_InputLeft.value = colorInputRight;
sectionOneH3.textContent = `background: linear-gradient(to right, ${colorInputRight}, ${colorInputLeft});`;
sectionOneP.textContent = "to right";
}
}
function reverseColorsHorizontal() {
const currentBackground = window.getComputedStyle(sectionTwo).background;
let colorInputTop = sec2_InputLeft.value;
let colorInputBottom = sec2_InputRight.value;
if(currentBackground.includes("to top")) {
let reversedBackground = currentBackground.replace("to top", "to bottom");
sectionTwo.style.background = reversedBackground;
sec2_InputLeft.value = colorInputBottom;
sec2_InputRight.value = colorInputTop;
sectionTwoH3.textContent = `background: linear-gradient(to bottom, ${colorInputTop}, ${colorInputBottom});`;
sectionTwoP.textContent = "to bottom";
} else if (!currentBackground.includes("to bottom")) {
sectionTwo.style.background = `linear-gradient(to top, ${colorInputTop}, ${colorInputBottom})`
sec2_InputRight.value = colorInputTop;
sec2_InputLeft.value = colorInputBottom;
sectionTwoH3.textContent = `background: linear-gradient(to top, ${colorInputTop}, ${colorInputBottom});`;
sectionTwoP.textContent = "to top";
}
}
function smoothScroll() {
const html = document.querySelector("html");
html.style.scrollBehavior = "smooth";
}
// events for section 1 //
sec1_InputLeft.addEventListener("input", changeColorsToRight);
sec1_InputRight.addEventListener("input", changeColorsToRight);
// events for section 2 //
sec2_InputLeft.addEventListener("input", changeColorsToBottom);
sec2_InputRight.addEventListener("input", changeColorsToBottom);
// events for btns //
copyBtn1.addEventListener("click", copyText);
copyBtn2.addEventListener("click", copyTextTwo);
sec1_reverseBtn.addEventListener("click", reverseColors);
sec2_reverseBtn.addEventListener("click", reverseColorsHorizontal);
changeColorsToRight();
changeColorsToBottom();
// I know this code is not very efficent but Im learning. Thank you for your patience :) //