-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
73 lines (59 loc) · 1.68 KB
/
main.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
// toggle
const toggle = document.querySelector(".toggle");
const menu = document.querySelector(".menu");
toggle.addEventListener("click", function () {
menu.classList.toggle("slide");
});
// smooth scroll
const menuLink = document.querySelectorAll(".link-js");
function smoothScroll() {
for (let i in menuLink) {
if (menuLink.hasOwnProperty(i)) {
menuLink[i].addEventListener("click", function (e) {
document.querySelector(menuLink[i].hash).scrollIntoView({
behavior: "smooth",
});
e.preventDefault();
});
}
}
}
smoothScroll();
// scroll to top
const toTop = document.querySelector(".top");
window.addEventListener("scroll", function () {
if (window.pageYOffset >= 300) {
toTop.classList.add("scroll");
} else {
toTop.classList.remove("scroll");
}
});
// committee
const seen = document.querySelectorAll(".see");
seen.forEach(function (klik) {
klik.addEventListener("click", function (e) {
e.target.previousElementSibling.firstElementChild.nextElementSibling.nextElementSibling.classList.toggle(
"add"
);
e.target.previousElementSibling.previousElementSibling.classList.toggle(
"add"
);
e.target.classList.add("fas");
e.target.classList.add("fa-angle-down");
});
});
// mode
const mode = document.querySelectorAll(".mode");
const html = document.querySelector("html");
html.dataset.mode = localStorage.getItem('mode');
mode.forEach(function (modes) {
modes.addEventListener("click", function () {
if (html.dataset.mode === "light") {
html.dataset.mode = "dark";
localStorage.setItem('mode', html.dataset.mode = "dark");
} else {
html.dataset.mode = "light";
localStorage.setItem('mode', html.dataset.mode = "light");
}
});
});