-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
59 lines (43 loc) · 1.73 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
const body = document.body;
const btnTheme = document.querySelector(".fa-moon");
const btnHamburger = document.querySelector(".fa-bars");
const addThemeClass = (bodyClass, btnClass) => {
body.classList.add(bodyClass);
btnTheme.classList.add(btnClass);
};
const getBodyTheme = localStorage.getItem("portfolio-theme");
const getBtnTheme = localStorage.getItem("portfolio-btn-theme");
addThemeClass(getBodyTheme, getBtnTheme);
const isDark = () => body.classList.contains("dark");
const setTheme = (bodyClass, btnClass) => {
body.classList.remove(localStorage.getItem("portfolio-theme"));
btnTheme.classList.remove(localStorage.getItem("portfolio-btn-theme"));
addThemeClass(bodyClass, btnClass);
localStorage.setItem("portfolio-theme", bodyClass);
localStorage.setItem("portfolio-btn-theme", btnClass);
};
const toggleTheme = () =>
isDark() ? setTheme("light", "fa-moon") : setTheme("dark", "fa-sun");
btnTheme.addEventListener("click", toggleTheme);
const displayList = () => {
const navUl = document.querySelector(".nav__list");
if (btnHamburger.classList.contains("fa-bars")) {
btnHamburger.classList.remove("fa-bars");
btnHamburger.classList.add("fa-times");
navUl.classList.add("display-nav-list");
} else {
btnHamburger.classList.remove("fa-times");
btnHamburger.classList.add("fa-bars");
navUl.classList.remove("display-nav-list");
}
};
btnHamburger.addEventListener("click", displayList);
const scrollUp = () => {
const btnScrollTop = document.querySelector(".scroll-top");
if (body.scrollTop > 500 || document.documentElement.scrollTop > 500) {
btnScrollTop.style.display = "block";
} else {
btnScrollTop.style.display = "none";
}
};
document.addEventListener("scroll", scrollUp);