toolbar.js 903 B

123456789101112131415161718192021222324
  1. function toolbarAdjustTop() {
  2. const toolbarHeight = document.getElementById("toolbar").offsetHeight;
  3. document.body.style.paddingTop = `${toolbarHeight}px`;
  4. const header = document.querySelector("header");
  5. const nav = document.querySelector("nav");
  6. [header, nav].forEach(element => {
  7. if (element && window.getComputedStyle(element).position === "fixed") {
  8. // Adjust the fixed header
  9. element.style.top = `${toolbarHeight}px`;
  10. }
  11. if (element) {
  12. const fixedElements = Array.from(element.querySelectorAll("*")).filter(el =>
  13. window.getComputedStyle(el).position === "fixed");
  14. fixedElements.forEach(el => {
  15. el.style.top = `${toolbarHeight}px`;
  16. });
  17. }
  18. });
  19. }
  20. window.addEventListener("load", toolbarAdjustTop);
  21. window.addEventListener("resize", toolbarAdjustTop);