-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
105 lines (70 loc) · 2.25 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
'use strict';
/**
* element toggle function
*/
const elemToggleFunc = function (elem) { elem.classList.toggle("active"); }
/**
* header sticky & go to top
*/
const header = document.querySelector("[data-header]");
const goTopBtn = document.querySelector("[data-go-top]");
window.addEventListener("scroll", function () {
if (window.scrollY >= 10) {
header.classList.add("active");
goTopBtn.classList.add("active");
} else {
header.classList.remove("active");
goTopBtn.classList.remove("active");
}
});
/**
* navbar toggle
*/
const navToggleBtn = document.querySelector("[data-nav-toggle-btn]");
const navbar = document.querySelector("[data-navbar]");
navToggleBtn.addEventListener("click", function () {
elemToggleFunc(navToggleBtn);
elemToggleFunc(navbar);
elemToggleFunc(document.body);
});
/**
* skills toggle
*/
const toggleBtnBox = document.querySelector("[data-toggle-box]");
const toggleBtns = document.querySelectorAll("[data-toggle-btn]");
const skillsBox = document.querySelector("[data-skills-box]");
for (let i = 0; i < toggleBtns.length; i++) {
toggleBtns[i].addEventListener("click", function () {
elemToggleFunc(toggleBtnBox);
for (let i = 0; i < toggleBtns.length; i++) { elemToggleFunc(toggleBtns[i]); }
elemToggleFunc(skillsBox);
});
}
/**
* dark & light theme toggle
*/
const themeToggleBtn = document.querySelector("[data-theme-btn]");
themeToggleBtn.addEventListener("click", function () {
elemToggleFunc(themeToggleBtn);
if (themeToggleBtn.classList.contains("active")) {
document.body.classList.remove("dark_theme");
document.body.classList.add("light_theme");
localStorage.setItem("theme", "light_theme");
} else {
document.body.classList.add("dark_theme");
document.body.classList.remove("light_theme");
localStorage.setItem("theme", "dark_theme");
}
});
/**
* check & apply last time selected theme from localStorage
*/
if (localStorage.getItem("theme") === "light_theme") {
themeToggleBtn.classList.add("active");
document.body.classList.remove("dark_theme");
document.body.classList.add("light_theme");
} else {
themeToggleBtn.classList.remove("active");
document.body.classList.remove("light_theme");
document.body.classList.add("dark_theme");
}