// JavaScript Document // ================================================= // ページロード時に実行 // ================================================= document.addEventListener('DOMContentLoaded', () => { const headerTarget = document.querySelector('header'); const headerhas = document.querySelector('.mod-freeHTML:has(#recruit-header)'); headerhas.classList.add('mod-freeHTML-header'); headerTarget.after(headerhas); var activeclass = "is-open"; const noscroll = "no-scroll"; const slideTrigger = document.getElementById("js-slideup-trigger"); //----------------------------------エントリーボタン if (slideTrigger) { slideTrigger.addEventListener("click", function () { slideTrigger.classList.toggle(activeclass); }); } //----------------------------------バーガーメニュー const trigger = document.getElementById("recruit-header-hamburger"); const menu = document.getElementById("recruit-header-drawer"); if (trigger && menu) { trigger.addEventListener("click", function () { const isActive = trigger.classList.contains(activeclass); trigger.classList.toggle(activeclass, !isActive); menu.classList.toggle(activeclass, !isActive); document.body.classList.toggle(noscroll, !isActive); }); } function btnFixed() { var fixedTarget = document.getElementById("recruit-header-hamburger"); // if(window.matchMedia("(max-width: 800px)").matches){ // fixedTarget = document.getElementById("recruit-header"); // } if(window.matchMedia("(max-width: 800px)").matches){ return; } // CSS変数 --header-height を取得(単位pxつき) var headerHeight = getComputedStyle(document.documentElement) .getPropertyValue("--header-height") .trim(); // "80px" → 80 に変換 var headerHeightNum = parseFloat(headerHeight); // スクロール量取得 var scrollY = window.scrollY; // クラス名 var fixedclass = "is-fixed"; // 判定 if (scrollY > headerHeightNum) { fixedTarget.classList.add(fixedclass); } else { fixedTarget.classList.remove(fixedclass); } } // 初期実行(ロード直後に反映したい場合) btnFixed(); // スクロールするたびに実行 window.addEventListener("scroll", function () { btnFixed(); }); //----------------------------------プルダウンメニュー var navTrigger = ".js-secondmenu-trigger"; var currentMode = null; // "sp" or "pc" function setupSecondMenuBehavior() { var isSp = window.matchMedia("(max-width: 1024px)").matches; var newMode = isSp ? "sp" : "pc"; // 同じモードなら何もしない(多重バインド防止) if (newMode === currentMode) return; currentMode = newMode; // 既存のイベントリスナーをリセット:要素をクローンして置き換え var oldTriggers = document.querySelectorAll(navTrigger); oldTriggers.forEach(function (trigger) { var newNode = trigger.cloneNode(true); trigger.parentNode.replaceChild(newNode, trigger); }); // 差し替え後の要素を再取得 var triggers = document.querySelectorAll(navTrigger); if (isSp) { // ----------------- SP:クリックでアコーディオン ----------------- triggers.forEach(function (trigger) { trigger.addEventListener("click", function () { var isActive = trigger.classList.contains(activeclass); // いったん全部閉じる triggers.forEach(function (t) { t.classList.remove(activeclass); }); // もともと閉じていたものだけ開く(= アコーディオン) if (!isActive) { trigger.classList.toggle(activeclass); } }); }); } else { // ----------------- PC:ホバーでアコーディオン ----------------- triggers.forEach(function (trigger) { trigger.addEventListener("mouseenter", function () { // 他を閉じてから自分だけ開く triggers.forEach(function (t) { t.classList.remove(activeclass); }); trigger.classList.add(activeclass); }); trigger.addEventListener("mouseleave", function () { trigger.classList.remove(activeclass); }); }); } } // 初期設定 setupSecondMenuBehavior(); var timer = 0; // リサイズ時にモード切り替え window.addEventListener("resize", function(){ clearTimeout(timer); timer = setTimeout(function(){ setupSecondMenuBehavior(); btnFixed(); }, 300); }); }); // ================================================= // firefoxバグ対応 // ================================================= function firefoxPatch() { const btnIcons = document.querySelectorAll('.btn-icon'); btnIcons.forEach((btnIcon) => { const parent = btnIcon.parentElement; // 親要素の高さを取得(px) const h = parent.getBoundingClientRect().height; if (!h) return; // aspect-ratio を無効化(auto)し、高さと同じ幅を与える btnIcon.style.aspectRatio = 'auto'; btnIcon.style.width = `${h}px`; btnIcon.style.height = `${h}px`; }); } function isFirefox() { // 1) User-Agent Client Hints が使える場合 if (navigator.userAgentData && Array.isArray(navigator.userAgentData.brands)) { // ※ Firefox は brands に出てこないケースが多いので、ここだけに依存しない const brandsText = navigator.userAgentData.brands .map((b) => `${b.brand} ${b.version}`) .join(' '); if (/firefox/i.test(brandsText)) return true; } // 2) 従来の UA 判定 const ua = navigator.userAgent || ''; // Firefox のみ(Seamonkey等を除外したいなら条件追加してください) return /firefox/i.test(ua) && !/seamonkey/i.test(ua); } // 実行(DOM が描画されて高さが取れるタイミングで) window.addEventListener('load', () => { if (isFirefox()) firefoxPatch(); }); // 画像遅延読み込み等で高さが後から確定する場合の保険(任意) window.addEventListener('resize', () => { if (isFirefox()) firefoxPatch(); }); // ================================================= // 横スクロール表示 // ================================================= $(function(){ var ua = navigator.userAgent; var isMobile = ua.indexOf('iPhone') > 0 || ua.indexOf('iPod') > 0 || (ua.indexOf('Android') > 0 && ua.indexOf('Mobile') > 0); if (isMobile) { document.querySelectorAll('.scroll').forEach(function (el) { el.addEventListener('touchstart', function () { el.classList.add('off'); }); }); } }); // ================================================= // fadein類 // ================================================= $(function(){ const fadeClasses = [ '.fadein', '.fadein-detail', '.fadein-t', '.fadein-b', '.fadein-l', '.fadein-r', '.fadein-blur', 'js-animation' ]; function handleScroll() { const scrollY = window.scrollY || window.pageYOffset; const windowHeight = window.innerHeight; fadeClasses.forEach(selector => { document.querySelectorAll(selector).forEach(el => { const imgPos = el.getBoundingClientRect().top + scrollY; if (scrollY > imgPos - windowHeight + windowHeight / 5) { el.classList.add('on'); } }); }); } window.addEventListener('scroll', handleScroll); handleScroll(); // ページ読み込み直後も判定 }); // ================================================= // アコーディオン // ================================================= $(function(){ $('.js-toggle').click(function(){ $(this).toggleClass('is-active'); $(this).next('.js-toggle-target').slideToggle(); }); }); // ================================================= // ソート機能付きリンク // ================================================= $(function(){ //data-categorylinkの値クエリ付きのリンクへ書き換える const sortLinks = document.querySelectorAll('[data-categorylink]'); if (!sortLinks.length) return; sortLinks.forEach(sortLink => { const categoryKey = sortLink.dataset.categorylink; const gethref = sortLink.getAttribute('href'); // 複数値を & で連結 const query = categoryKey .split(',') .map(v => v.trim()) .join('&'); const addHref = gethref + '?' + query; sortLink.setAttribute('href', addHref); }); }); $(function(){ // data-categorylinkcatch を持つ要素がある場合、読み込み時にクリックイベント const getLinks = document.querySelectorAll('[data-categorylinkcatch]'); if (!getLinks.length) return; const urlParam = location.search.substring(1); // 例: "web&senior" if (!urlParam) return; // ["web", "senior"] const values = urlParam .split('&') .map(v => v.trim()) .filter(Boolean); getLinks.forEach(getLink => { const type = getLink.dataset.categorylinkcatch; // 例: "web" if (values.includes(type)) { getLink.dispatchEvent(new PointerEvent('click')); } }); });