$(window).scroll(function () {//追従バナー
  var pos = document.body.clientHeight / 100;
  if ($(this).scrollTop() > pos) {
    $('.btn__float').fadeIn();
  } else {
    $('.btn__float').fadeOut();
  }
});

$(function () { // スクロールイベント
  scrollToggleClass();
  $(window).on('scroll', function () {
    scrollToggleClass();
  });
  function scrollToggleClass() {
    $('.js-scroll').each(function () {
      let target = $(this).offset().top;
      let scroll = $(window).scrollTop();
      let windowHeight = $(window).height();
      if (scroll > target - windowHeight) {
        $(this).addClass('is-active');
      } else {
        $(this).removeClass('is-active');
      }
    });
  }
});

(function(){//モーダル
  let modalState = false;
  window.addEventListener("popstate", (e) => {
    if (modalState || e.state !== "pushed")
      return;
    $("#js-modal").fadeIn();
    $(".js-modal-close").on("click", ()=> {
      $("#js-modal").fadeOut();
      modalState = true;
      window.history.back();
    })
  });
  const onload = () => {
    window.history.replaceState("pushed", null, null);
    const entries = performance.getEntriesByType("navigation");
    if (entries.some((item) => item.type === "reload")) {
      return;
    } else {
      window.history.pushState("pushed", null, null);
    }
  };
  window.addEventListener("load", ()=> {
    onload();
  });
})();