htmly/system/resources/js/toolbar.js
Dan aeec0910ff Improve toolbar and menu
Sometimes if we have a menu with a `fixed` position then it will overlap with the toolbar. This is trying to fix it.
2025-04-21 18:30:12 +07:00

24 lines
No EOL
903 B
JavaScript

function toolbarAdjustTop() {
const toolbarHeight = document.getElementById("toolbar").offsetHeight;
document.body.style.paddingTop = `${toolbarHeight}px`;
const header = document.querySelector("header");
const nav = document.querySelector("nav");
[header, nav].forEach(element => {
if (element && window.getComputedStyle(element).position === "fixed") {
// Adjust the fixed header
element.style.top = `${toolbarHeight}px`;
}
if (element) {
const fixedElements = Array.from(element.querySelectorAll("*")).filter(el =>
window.getComputedStyle(el).position === "fixed");
fixedElements.forEach(el => {
el.style.top = `${toolbarHeight}px`;
});
}
});
}
window.addEventListener("load", toolbarAdjustTop);
window.addEventListener("resize", toolbarAdjustTop);