-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
22 lines (18 loc) · 714 Bytes
/
Copy pathscript.js
File metadata and controls
22 lines (18 loc) · 714 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
document.addEventListener("DOMContentLoaded", () => {
const year = document.querySelector("#current-year");
if (year) year.textContent = new Date().getFullYear();
const reduceMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
document.querySelectorAll('a[href^="#"]').forEach((link) => {
link.addEventListener("click", (event) => {
const selector = link.getAttribute("href");
if (!selector || selector === "#") return;
const target = document.querySelector(selector);
if (!target) return;
event.preventDefault();
target.scrollIntoView({
behavior: reduceMotion ? "auto" : "smooth",
block: "start",
});
});
});
});