-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
50 lines (41 loc) · 1.11 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
var toggle_btn;
var big_wrapper;
var hamburger_menu;
function declare() {
toggle_btn = document.querySelector(".toggle-btn");
big_wrapper = document.querySelector(".big-wrapper");
hamburger_menu = document.querySelector(".hamburger-menu");
}
const main = document.querySelector("main");
declare();
let dark = false;
function toggleAnimation() {
// Clone the wrapper
dark = !dark;
let clone = big_wrapper.cloneNode(true);
if (dark) {
clone.classList.remove("light");
clone.classList.add("dark");
} else {
clone.classList.remove("dark");
clone.classList.add("light");
}
clone.classList.add("copy");
main.appendChild(clone);
document.body.classList.add("stop-scrolling");
clone.addEventListener("animationend", () => {
document.body.classList.remove("stop-scrolling");
big_wrapper.remove();
clone.classList.remove("copy");
// Reset Variables
declare();
events();
});
}
function events() {
toggle_btn.addEventListener("click", toggleAnimation);
hamburger_menu.addEventListener("click", () => {
big_wrapper.classList.toggle("active");
});
}
events();