mirror of
https://github.com/pepaskopec-blip/skopec.dev.git
synced 2026-10-27 15:14:33 +00:00
Initial commit
This commit is contained in:
parent
d74e3f6e14
commit
aa4b87399c
15 changed files with 1726 additions and 0 deletions
51
script.js
Normal file
51
script.js
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
(() => {
|
||||
const yearNodes = document.querySelectorAll("[data-year]");
|
||||
const year = String(new Date().getFullYear());
|
||||
yearNodes.forEach((node) => {
|
||||
node.textContent = year;
|
||||
});
|
||||
|
||||
const toggle = document.querySelector(".nav-toggle");
|
||||
const nav = document.querySelector("#site-nav");
|
||||
|
||||
if (toggle && nav) {
|
||||
const setOpen = (open) => {
|
||||
nav.classList.toggle("is-open", open);
|
||||
toggle.setAttribute("aria-expanded", open ? "true" : "false");
|
||||
toggle.setAttribute("aria-label", open ? "Close menu" : "Open menu");
|
||||
};
|
||||
|
||||
toggle.addEventListener("click", () => {
|
||||
setOpen(!nav.classList.contains("is-open"));
|
||||
});
|
||||
|
||||
nav.querySelectorAll("a").forEach((link) => {
|
||||
link.addEventListener("click", () => setOpen(false));
|
||||
});
|
||||
|
||||
document.addEventListener("keydown", (event) => {
|
||||
if (event.key === "Escape") setOpen(false);
|
||||
});
|
||||
}
|
||||
|
||||
const revealItems = document.querySelectorAll(".reveal");
|
||||
if (!revealItems.length) return;
|
||||
|
||||
if (!("IntersectionObserver" in window)) {
|
||||
revealItems.forEach((el) => el.classList.add("is-visible"));
|
||||
return;
|
||||
}
|
||||
|
||||
const observer = new IntersectionObserver(
|
||||
(entries, obs) => {
|
||||
entries.forEach((entry) => {
|
||||
if (!entry.isIntersecting) return;
|
||||
entry.target.classList.add("is-visible");
|
||||
obs.unobserve(entry.target);
|
||||
});
|
||||
},
|
||||
{ threshold: 0.12, rootMargin: "0px 0px -8% 0px" }
|
||||
);
|
||||
|
||||
revealItems.forEach((el) => observer.observe(el));
|
||||
})();
|
||||
Loading…
Add table
Add a link
Reference in a new issue