-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
40 lines (34 loc) · 910 Bytes
/
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
// Scroll to top
const scrolltp = document.querySelector("#scrolltp");
scrolltp.addEventListener("click", function () {
window.scrollTo({
top: 0,
left: 0,
behavior: "smooth",
});
});
window.addEventListener("scroll", function () {
if (window.scrollY >= 700) {
scrolltp.style.opacity = 1;
} else {
scrolltp.style.opacity = 0;
}
});
// Theme
const themeToggle = document.querySelector(".checkbox");
const body = document.querySelector("body");
const darkmode = localStorage.getItem("dark");
if (darkmode) {
// Get Dark mode from local storage
body.classList.add("dark");
themeToggle.checked = true;
}
themeToggle.addEventListener("change", function () {
body.classList.toggle("dark");
// Set Local storage for Dark Mode
if (body.classList.contains("dark")) {
localStorage.setItem("dark", "active");
} else {
localStorage.removeItem("dark");
}
});