document.addEventListener("DOMContentLoaded", () => { /** * 固定 */ //const mvSection = document.querySelector(".mv"); const mvBanner = document.getElementById("mvBanner"); const bsnHeader = document.querySelector(".bsn .header"); const bsnmain = document.querySelector(".bsn"); window.addEventListener("scroll", () => { const scrollPosition = window.scrollY || document.documentElement.scrollTop; if (scrollPosition >= 180) { if (mvBanner) { mvBanner.style.position = "fixed"; mvBanner.style.top = `${bsnHeader.offsetHeight}px`; //mvBanner.style.left = "calc(100% - 8.59375vw)"; } bsnHeader.classList.toggle("fixed"); bsnHeader.style.position = "fixed"; bsnHeader.style.top = "0px"; bsnmain.style.marginTop = "60px"; } else { if (mvBanner) { mvBanner.style.position = "absolute"; mvBanner.style.top = "0px"; } bsnHeader.style.position = "relative"; bsnmain.style.marginTop = "0px"; } }); /** * ヘッダーのナビゲーション表示 */ if (window.innerWidth < 1024) { if (bsnHeader) { bsnHeader.addEventListener("click", () => { bsnHeader.classList.toggle("active"); document.addEventListener("click", (event) => { if (!bsnHeader.contains(event.target)) { bsnHeader.classList.remove("active"); } }); }); } } /** * 診断結果振り分け */ const showResultButton = document.querySelector(".btn-show-result"); if (showResultButton) { showResultButton.addEventListener("click", function (e) { e.preventDefault(); const selectedValues = {}; const radioButtons = document.querySelectorAll('.qa_item input[type="radio"]:checked'); //診断結果ページ遷移先リスト const destinationList = [ 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 4, 3, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 9, 9, 8, 8, 9, 9, 8, 8, 9, 9, 8, 8, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, ]; // ラジオボタンの値を取得 radioButtons.forEach((radio) => { selectedValues[radio.name] = radio.value; }); // 全部選択したかチェック const totalQuestions = document.querySelectorAll(".qa_item").length; if (Object.keys(selectedValues).length < totalQuestions) { alert("全ての質問に回答してください。"); return; } // 回答を2進数の文字列にする let binaryString = ""; for (let i = 1; i <= Object.keys(selectedValues).length; i++) { binaryString += selectedValues[`q${i}`]; } // 2進数を10進数に変換 let answers = parseInt(binaryString, 2); // 結果ページへ遷移 const result = (window.location.href = `result/${String(destinationList[answers]).padStart( 2, "0" )}/index.aspx`); return false; }); } });