actuel-inactuel/assets/js/script.js

53 lines
1.3 KiB
JavaScript
Raw Normal View History

2024-01-26 13:42:00 +01:00
const remFactor = 16;
const verticalUnit = 1.3 * remFactor;
2024-03-09 11:27:10 +01:00
function toggleTab(data, tab) {
if (data.activeTab === tab) {
scrollToElem("body");
setTimeout(() => {
data.activeTab = "";
data.isOpen = false;
2024-03-09 11:27:10 +01:00
}, 200);
} else {
data.activeTab = tab;
data.isOpen = true;
2024-03-09 11:27:10 +01:00
scrollToElem(".active-tab");
}
2024-01-25 17:05:19 +01:00
}
2024-01-25 18:34:32 +01:00
function scrollToElem(selector) {
document.querySelector(".active-tab").scrollTop = 0;
2024-01-25 18:34:32 +01:00
setTimeout(() => {
2024-03-09 11:27:10 +01:00
const yOffset = -7 * verticalUnit;
2024-01-25 18:34:32 +01:00
const elem = document.querySelector(selector);
const top = elem.getBoundingClientRect().top;
window.scrollTo({
top: top + window.scrollY + yOffset,
behavior: "smooth",
});
}, 100);
2024-01-25 17:05:19 +01:00
}
document.addEventListener("DOMContentLoaded", () => {
function toggleLogoState() {
2024-01-25 18:34:32 +01:00
const scrollY = window.scrollY || window.pageYOffset;
2024-01-25 17:05:19 +01:00
if (scrollY > 10) {
document.querySelector("#main-header").classList.add("minimized");
2024-01-25 17:05:19 +01:00
} else {
document.querySelector("#main-header").classList.remove("minimized");
2024-01-25 17:05:19 +01:00
}
}
window.addEventListener("scroll", () => {
2024-01-25 18:34:32 +01:00
toggleLogoState();
});
2024-03-10 19:24:24 +01:00
if (
navigator.userAgent.toLowerCase().includes("safari") &&
window.innerWidth < 800
) {
document.querySelector("#tabs").classList.add("safari");
}
2024-01-25 18:34:32 +01:00
});