-
Notifications
You must be signed in to change notification settings - Fork 153
/
app.js
81 lines (65 loc) · 2.05 KB
/
app.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
// Select The Elements
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();
function toggleAnimation() {
// Clone the wrapper
console.log(" theme "+localStorage.getItem("theme"));
if (localStorage.getItem("theme") === null)
{ localStorage.setItem("theme", "dark"); }
let clone = big_wrapper.cloneNode(true);
if (localStorage.getItem("theme") === "light") {
clone.classList.remove("light");
clone.classList.add("dark");
localStorage.setItem("theme", "dark");
} else {
clone.classList.remove("dark");
clone.classList.add("light");
localStorage.setItem("theme", "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");
console.log(" theme "+localStorage.getItem("theme"));
// Reset Variables
declare();
events();
});
}
function events() {
toggle_btn.addEventListener("click", toggleAnimation);
hamburger_menu.addEventListener("click", () => {
big_wrapper.classList.toggle("active");
});
}
// restart with same
console.log(" theme "+localStorage.getItem("theme"));
let clone = big_wrapper.cloneNode(true);
if (localStorage.getItem("theme") === "light") {
clone.classList.add("light");
} else {
clone.classList.add("dark");
}
clone.classList.add("copy");
main.appendChild(clone);
document.body.classList.add("stop-scrolling");
document.body.classList.remove("stop-scrolling");
big_wrapper.remove();
clone.classList.remove("copy");
document.body.classList.remove("stop-scrolling");
big_wrapper.remove();
clone.classList.remove("copy");
// Reset Variables
declare();
events();