Sha256: 4dbef95d258106ad10e334086d51ec78738539ddb19374a3cf76f8cd6acd321a

Contents?: true

Size: 1.03 KB

Versions: 7

Compression:

Stored size: 1.03 KB

Contents

document.addEventListener("DOMContentLoaded", function () {
  const sections = document.querySelectorAll("section");
  const navDots = document.querySelectorAll("#dot-nav .dot");

  function onScroll() {
    let currentSection = "";

    sections.forEach((section) => {
      const sectionTop = section.offsetTop;
      if (pageYOffset >= sectionTop - 120) {
        // Ajusta el valor segĂșn sea necesario
        currentSection = section.getAttribute("id");
      }
    });

    navDots.forEach((dot) => {
      dot.classList.remove("bg-gray-800");
      if (dot.getAttribute("href") === `#${currentSection}`) {
        dot.classList.add("bg-gray-800");
      }
    });
  }

  function smoothScroll(target) {
    document.querySelector(target).scrollIntoView({
      behavior: "smooth",
    });
  }

  navDots.forEach((dot) => {
    dot.addEventListener("click", function (event) {
      event.preventDefault();
      const target = this.getAttribute("href");
      smoothScroll(target);
    });
  });

  window.addEventListener("scroll", onScroll);
});

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
awesome-jekyll-theme-1.2.1 assets/js/dot-navigation.js
awesome-jekyll-theme-1.2.0 assets/js/dot-navigation.js
awesome-jekyll-theme-1.1.0 assets/js/dot-navigation.js
awesome-jekyll-theme-1.0.1 assets/js/dot-navigation.js
awesome-jekyll-theme-1.0.0 assets/js/dot-navigation.js
awesome-jekyll-theme-0.3.1 assets/js/dot-navigation.js
awesome-jekyll-theme-0.3.0 assets/js/dot-navigation.js