-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
29 lines (23 loc) · 819 Bytes
/
Copy pathscript.js
File metadata and controls
29 lines (23 loc) · 819 Bytes
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
const btn = document.getElementById("DarkModeBtn");
btn.addEventListener("click", () => {
document.body.classList.toggle("dark-mode");
if (document.body.classList.contains("dark-mode")) {
btn.textContent = "Light Mode";
} else {
btn.textContent = "Dark Mode";
}
});
document.querySelectorAll('.nav__links a').forEach(link => {
link.addEventListener("click", function(e) {
e.preventDefault();
document.querySelector(this.getAttribute("href"))
.scrollIntoView({ behavior: "smooth" });
});
});
const topBtn = document.getElementById("scrollTopBtn");
window.addEventListener("scroll", () => {
topBtn.style.display = window.scrollY > 400 ? "block" : "none";
});
topBtn.addEventListener("click", () => {
window.scrollTo({ top: 0, behavior: "smooth" });
});