forked from ttatoni26/trajan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
74 lines (61 loc) · 1.82 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
const toggleButton = document.getElementsByClassName("toggle-button")[0];
const navbarLinks = document.getElementsByClassName("navbar-links")[0];
const links = document.querySelectorAll("a");
toggleButton.addEventListener("click", () => {
navbarLinks.classList.toggle("active");
});
// dark mode
const enableDarkMode = () => {
document.body.classList.add("darkmode");
links.forEach((link, index) => {
link.classList.add("darkmodeLink");
});
localStorage.setItem("darkMode", "enabled");
};
const disableDarkMode = () => {
document.body.classList.remove("darkmode");
links.forEach((link, index) => {
link.classList.remove("darkmodeLink");
});
localStorage.setItem("darkMode", null);
};
let darkMode = localStorage.getItem("darkMode");
const darkModeToggle = document.querySelector("#darkBtn");
if (darkMode === "enabled") {
enableDarkMode();
}
darkModeToggle.addEventListener("click", () => {
darkMode = localStorage.getItem("darkMode");
if (darkMode !== "enabled") {
enableDarkMode();
console.log(darkMode);
} else {
disableDarkMode();
console.log(darkMode);
}
});
// progress bar
const progressBar = document.querySelector("#progress-bar");
const main = document.querySelector("main");
const nav = document.querySelector(".navbar")
const animateProgressBar = () => {
let scrollDistance = -main.getBoundingClientRect().top;
let progressWidth =
(scrollDistance /
(main.getBoundingClientRect().height -
document.documentElement.clientHeight)) *
100;
let value = Math.floor(progressWidth);
progressBar.style.width = `${value}%`;
if (value < 0) {
progressBar.style.width = "0%";
}
};
window.addEventListener("scroll", animateProgressBar);
// animation
var slideUp = {
distance: '150%',
origin: 'left',
opacity: null,
};
ScrollReveal().reveal('section', slideUp);