"use strict"; // アニメーションの発火設定 emergence.init({ reset: false, offsetTop: 100, offsetBottom: 120, }); // 追従メニュー // ============================ var isFollowMenuVisible = false; window.addEventListener('load', function () { // SPのリンクリスト開閉 [].slice.call(document.querySelectorAll(".js-follow-menu-btn")).forEach(function (e) { e.addEventListener('click', function () { var linkListHeight = document.querySelector('.js-follow-menu-list').clientHeight; var style = window.getComputedStyle(document.body); var bodyPB = style.getPropertyValue('padding-bottom'); bodyPB = Number(bodyPB.replace('px', '')); if (e.classList.contains('active')) { // リンクリスト閉じる e.classList.remove('active'); [].slice.call(document.querySelectorAll(".js-follow-menu-list")).forEach(function (ele) { if (ele.classList.contains('active')) { ele.classList.remove('active'); document.body.style.paddingBottom = ''; } }); } else { // リンクリスト開く e.classList.add('active'); [].slice.call(document.querySelectorAll(".js-follow-menu-list")).forEach(function (ele) { if (!ele.classList.contains('active')) { ele.classList.add('active'); document.body.style.paddingBottom = String(bodyPB + linkListHeight) + 'px'; } }); } }, false); }); // 閉じるボタン [].slice.call(document.querySelectorAll(".js-follow-menu-close")).forEach(function (e) { e.addEventListener('click', function () { [].slice.call(document.querySelectorAll(".js-follow-menu")).forEach(function (ele) { ele.classList.add('hide'); }); }); }); // ある程度スクロールしてから表示 var timer = null; var scrollMenu = this.document.getElementById('follow-menu'); function visibleFollowMenu() { clearTimeout(timer); timer = setTimeout(function () { if (scrollMenu) { if (window.pageYOffset > 200) { scrollMenu.classList.remove('unvisible'); } else { scrollMenu.classList.add('unvisible'); } } }, 100); } visibleFollowMenu(); document.addEventListener('scroll', visibleFollowMenu, { passive: true }); }); // ハンバーガーメニュー // ============================ var hamburgerBtn = document.querySelector('.js-hamburger-btn'); var hamburgerCloseBtn = document.querySelector('.js-hamburger-close'); var hamburgerMenu = document.getElementById('hamburger'); // 開閉処理 if (hamburgerBtn) { hamburgerBtn.addEventListener('click', function (e) { if (e.currentTarget.classList.contains('active')) { // ハンバーガー閉じる // hamburgerMenu.style.display = 'none'; hamburgerMenu.classList.remove('active'); e.currentTarget.classList.remove('active'); hamburgerMenu.style.top = ''; // 背景がスクロールされてしまうのを解除 document.body.style.height = ''; document.body.style.overflow = ''; } else { // ハンバーガー開く // hamburgerMenu.style.display = 'block'; hamburgerMenu.classList.add('active') e.currentTarget.classList.add('active'); var positionTop = window.pageYOffset; var hamburgerTop = hamburgerMenu.getBoundingClientRect().top; var up = hamburgerTop - positionTop; if(up < 0) { up = 0; } hamburgerMenu.style.top = up+'px'; // 背景がスクロールされてしまうのを防ぐ document.body.style.height = '100vh'; document.body.style.overflow = 'hidden'; } }, false); } // クローズ処理 if (hamburgerCloseBtn) { hamburgerCloseBtn.addEventListener('click', function (e) { hamburgerMenu.classList.remove('active'); hamburgerBtn.classList.remove('active'); // 背景がスクロールされてしまうのを解除 document.body.style.height = ''; document.body.style.overflow = ''; }); } // クリックが背景に通らないように if (hamburgerMenu) { hamburgerMenu.addEventListener('click', function (e) { event.stopPropagation(); return false; }, false); } // モーダル // ============================ var moviePlayer = undefined; // モーダル開く [].slice.call(document.querySelectorAll(".js-modal-open")).forEach(function (e) { e.addEventListener('click', function () { var targetID = "modal--".concat(e.dataset.modal); var targetModal = document.getElementById(targetID); if (targetModal && !targetModal.classList.contains('active')) { targetModal.classList.add('active'); if (e.dataset.modal === 'movie') { // 動画モーダルの場合 var myWidth = window.innerWidth; moviePlayer = new YT.Player('ytplayer', { height: '517', width: '920', videoId: e.dataset.movieid }); } // 背景がスクロールされてしまうのを防ぐ document.body.style.height = '100vh'; document.body.style.overflow = 'hidden'; } }, false); }); // モーダル閉じる [].slice.call(document.querySelectorAll(".js-modal")).forEach(function (e) { e.addEventListener('click', function () { event.stopPropagation(); closeModal(); }); }); [].slice.call(document.querySelectorAll(".js-modal-close")).forEach(function (e) { e.addEventListener('click', function () { event.stopPropagation(); closeModal(); }); }); // 閉じる処理 var closeModal = function closeModal() { [].slice.call(document.querySelectorAll(".js-modal")).forEach(function (modal) { modal.classList.remove('active'); }); // 背景がスクロールされてしまうのを解除 document.body.style.height = ''; document.body.style.overflow = ''; // 動画は初期化 moviePlayer = undefined; [].slice.call(document.querySelectorAll(".modal__movie-wrap")).forEach(function (movieWrap) { // 空にして、yyPlayerを置き直す movieWrap.textContent = null; var player = document.createElement('div'); player.setAttribute('id', 'ytplayer'); movieWrap.appendChild(player); }); }; // クリック の背景通過を防ぐ [].slice.call(document.querySelectorAll(".js-modal-inner")).forEach(function (e) { e.addEventListener('click', function (ele) { ele.stopPropagation(); return false; }); }); // トップに戻る // ============================ var goTopBtn = document.getElementById('go-top'); if (goTopBtn) { goTopBtn.addEventListener('click', function () { goFunc(); return false; }); } // トップに戻る処理 var goFunc = function goFunc() { var nowY = window.pageYOffset; window.scrollTo(0, Math.floor(nowY * 0.9)); if (nowY > 0) { window.setTimeout(goFunc, 10); } }; // UUIDの作成Func // ============================ function generateUuid() { var chars = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".split(""); for (var i = 0, len = chars.length; i < len; i++) { switch (chars[i]) { case "x": chars[i] = Math.floor(Math.random() * 16).toString(16); break; case "y": chars[i] = (Math.floor(Math.random() * 4) + 8).toString(16); break; } } return chars.join(""); }