コード例 #1
0
ファイル: main-menu.js プロジェクト: zoxon/gulp-front
      link.addEventListener("click", event => {
        event.preventDefault();

        const title = link.innerText;
        const url = link.getAttribute("href");
        const page = url.split("#")[0];
        const hash = url.split("#")[1];
        const target = document.querySelector(`a[name="${hash}"], #${hash}`);

        if (window.location.pathname !== `/${page}`) {
          window.location = url;
        }

        if (target) {
          let options = { duration };
          const to = getOffsetTop(target) - offset;

          scrollTo({ to, options });

          if (window.history.pushState) {
            window.history.pushState(null, title, url);
          } else {
            window.location = url;
          }
        }
      });
コード例 #2
0
ファイル: scroll-top.js プロジェクト: zoxon/gulp-front
  onClickHandler(event) {
    event.preventDefault();

    const options = { duration: this.options.duration };
    const to = 0;

    scrollTo({ to, options });
  }