-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
36 lines (32 loc) · 995 Bytes
/
Copy pathscript.js
File metadata and controls
36 lines (32 loc) · 995 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
29
30
31
32
33
34
35
36
// Checkbox toggle logic
document.querySelectorAll(".checkbox").forEach(box => {
box.addEventListener("click", () => {
box.classList.toggle("checked");
});
});
// Smooth scrolling for anchor links
document.querySelectorAll('a[href^="#"]').forEach(link => {
link.addEventListener("click", function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute("href"));
if (target) {
target.scrollIntoView({ behavior: "smooth" });
}
});
});
// Scroll-to-top button logic
const scrollBtn = document.getElementById("scrollToTopBtn");
if (scrollBtn) {
// Show or hide the button based on scroll position
window.addEventListener("scroll", () => {
if (window.scrollY > 300) {
scrollBtn.classList.remove("hidden");
} else {
scrollBtn.classList.add("hidden");
}
});
// Scroll to top when button is clicked
scrollBtn.addEventListener("click", () => {
window.scrollTo({ top: 0, behavior: "smooth" });
});
}