-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathscript.js
49 lines (43 loc) · 1.31 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
// Redirect to the camera preview page
function goToCameraPage() {
window.location.href = "camera.html";
}
// Select the scroll-to-top button
const scrollToTopBtn = document.getElementById("scrollToTopBtn");
// Function to toggle the visibility of the button
window.addEventListener("scroll", () => {
if (window.scrollY > 100) {
scrollToTopBtn.style.display = "flex";
} else {
scrollToTopBtn.style.display = "none";
}
});
// Function to scroll to the top
scrollToTopBtn.addEventListener("click", () => {
window.scrollTo({
top: 0,
behavior: "smooth"
});
});
const toggleButton = document.getElementById("darkModeToggle");
const body = document.body;
// Apply dark mode if saved in localStorage
if (localStorage.getItem("theme") === "dark") {
body.classList.add("dark-mode");
if (toggleButton) {
toggleButton.textContent = "☀️ Light Mode";
}
}
// Toggle Dark Mode
if (toggleButton) {
toggleButton.addEventListener("click", () => {
body.classList.toggle("dark-mode");
if (body.classList.contains("dark-mode")) {
localStorage.setItem("theme", "dark");
toggleButton.textContent = "☀️ Light Mode";
} else {
localStorage.setItem("theme", "light");
toggleButton.textContent = "🌙 Dark Mode";
}
});
}