jQuery(function ($) { // 履歴復元によるスクロール位置を無効化(←ここ重要!) if ('scrollRestoration' in history) { history.scrollRestoration = 'manual'; } // ハンバーガーメニュー $('.js-hamburger-btn').click(function () { $(this).toggleClass('open'); if ($(this).hasClass('open')) { $('.js-drawer').fadeIn(); } else { $('.js-drawer').fadeOut(); } }); $(window).on('load resize', function () { const wid = $(window).width(); if (wid >= 768) { $('.js-drawer').css('display', 'none'); $('.js-hamburger-btn').removeClass('open'); } }); $(window).on("scroll", function () { let mvHeight = $(".p-mv").outerHeight(); let scrollTop = $(window).scrollTop(); if (scrollTop > mvHeight) { $("#header").addClass("is-scroll"); } else { $("#header").removeClass("is-scroll"); } }); // 最初のコンテンツは表示 $(".js-tab").on("click", function () { $(".current").removeClass("current"); $(this).addClass("current"); const index = $(this).index(); $(".js-content").hide().eq(index).fadeIn(300); }); // スムーススクロール(クリック時、ヘッダー考慮) $(document).on('click', 'a[href*="#"]', function (e) { let href = $(this).attr('href'); let target = $(href); if (!target.length) return; let header = $('header').innerHeight(); let position = target.offset().top - header; e.preventDefault(); // デフォルトのアンカー動作を無効化 $('html, body').stop().animate({ scrollTop: position }, 400, 'swing'); return false; }); // ページ読み込み時にハッシュがあればスクロール(ヘッダー考慮) $(window).on('load', function () { let headerHeight = $('header').innerHeight(); let urlHash = location.hash; if (urlHash) { let target = $(urlHash); if (target.length) { let position = target.offset().top - headerHeight; $('html, body').animate({ scrollTop: position }, 400, 'swing'); } } }); // スクロール時に `.js-title` が 80% の位置に来たら `.is-active` を追加 $(window).on("scroll", function () { $(".js-title").each(function () { let $this = $(this); if (!$this.hasClass("is-active")) { let elementTop = $this.offset().top; let viewportBottom = $(window).scrollTop() + $(window).height() * 0.8; if (elementTop < viewportBottom) { $this.addClass("is-active"); } } }); }); // 初期スクロール判定 $(window).trigger("scroll"); });