Skip to main content

Header menu covering the anchors

Comments

5 comments

  • Ariel H.

    Hi,

    Thank you for reaching out to us.

    Unfortunately, we do not currently have a permanent solution for this issue. However, we have recently received a similar request and will forward it to our developers as a feature improvement for upcoming updates. In the meantime, we recommend implementing a temporary solution by adding a margin or a spacer element, as suggested, until a more suitable resolution is found.

    Sorry for the inconvenience.

    Best regards,
    Ariel H.

    0
  • Stefan Fröhlich

    Any solution by now?

     

    0
  • KC George

    Hello Stefan,

    Have a look at https://jmp.sh/share/AxNJabIMPqcoPcr7AWu6, where we explain a workaround for resolving issues that can occur when using anchor links together with a sticky header.

    The workaround provides a practical way to ensure that visitors are taken to the correct position on the page when they click an anchor link, rather than having the target content hidden behind the sticky header. Kindly follow the steps outlined in the guide to implement the workaround on your website.

    0
  • Stefan Fröhlich

    Thank you very much George, I've seen the video.
    This is a quick and dirty solution for simple websites with little maintenance.

    But for a website with many pages with many blocks in three different languages, this is really messy and lots of work for a simple bug that could be fixed in your JavaScript...

    Any hope you'll be fixing this bug in the near future?

    0
  • KC George

    Hello Stefan,

    We also created the following JS code. You could also try this as an alternate solution. 

    Open any Brizy page in the editor, drag and drop the "Embed" element into the global footer, and paste the following script.

    <script>
    document.addEventListener(
      "click",
      function (event) {
        // Do not interfere with modified clicks.
        if (
          event.button !== 0 ||
          event.ctrlKey ||
          event.metaKey ||
          event.shiftKey ||
          event.altKey
        ) {
          return;
        }

        const link = event.target.closest('a[href*="#"]');

        if (!link) return;

        const url = new URL(link.href, window.location.href);

        // Only process anchor links pointing to the current page.
        if (
          url.origin !== window.location.origin ||
          url.pathname !== window.location.pathname ||
          url.search !== window.location.search ||
          !url.hash ||
          url.hash === "#"
        ) {
          return;
        }

        const id = decodeURIComponent(url.hash.substring(1));
        const target = document.getElementById(id);

        if (!target) return;

        event.preventDefault();
        event.stopImmediatePropagation();

        const header = document.getElementById("header");

            const offset = header
          ? header.getBoundingClientRect().height
          : 50; // adjust as needed until you’re satisfied with the spacing between the header and the content blocks.

        const destination =
          target.getBoundingClientRect().top +
          window.scrollY -
          offset;

        window.scrollTo({
          top: destination,
          behavior: "smooth"
        });

        history.pushState(null, "", url.hash);
      },
      true
    );
    </script>


    After adding the code, save your work and clear any website and browser cache and check if this helps resolve the issue with the anchor block visibility.

    0

Please sign in to leave a comment.