~kvikshaug/kvikshaug.no

959d1e829d3c40a3295520b8ea5b7f646385c3ab — Ali Kaafarani 2 years ago e8d9220
Toggle active nav element on small screens
2 files changed, 8 insertions(+), 3 deletions(-)

M assets/sass/_layout_responsive.scss
M script/navigation.js
M assets/sass/_layout_responsive.scss => assets/sass/_layout_responsive.scss +4 -1
@@ 14,7 14,6 @@
    justify-content: center;
    padding: 10px;
    width: 100%;
    border-top: 1px solid #1b1b1b;
    background-color: white;
    font-size: 14px;
    text-align: center;


@@ 24,6 23,10 @@
      flex-direction: column;
      row-gap: 6px;
      color: #1b1b1b;

      &.active {
        color: #bf3211;
      }
    }
  }


M script/navigation.js => script/navigation.js +4 -2
@@ 8,10 8,12 @@
        rect.bottom >= document.documentElement.clientHeight / 2;

      document
        .querySelector(
        .querySelectorAll(
          `nav a[href='#${element.getAttribute("data-trigger-nav")}']`
        )
        .classList.toggle("active", isInViewport);
        .forEach((element) => {
          element.classList.toggle("active", isInViewport);
        });
    });
  };
  document.addEventListener("scroll", handler);