$(function() { //--------------------------------------------- // ハンバーガーメニュー開閉 //--------------------------------------------- $('.toggle').on('click',function(){ $(this).toggleClass('active'); $('#header_nav').fadeToggle(500); $('#header_nav').toggleClass('bg-Cross-blue'); }); //ページ内リンククリック時にハンバーガーメニューを閉じる if (window.matchMedia('(max-width: 600px)').matches) { $('#header_nav a[href]').on('click', function() { $('.toggle').trigger('click'); }); } //--------------------------------------------- // ハンバーガーメニューが開いている時はサイトをスクロールさせない //--------------------------------------------- $('.toggle').click(function() { $('body').toggleClass("active"); }); //--------------------------------------------- // 具体例開閉 //--------------------------------------------- if (window.matchMedia("(max-width: 1180px)").matches) { $('.btn-case').on('click',function(){ $('.active-hide-list').fadeToggle(300); $('.active-hide-list').toggleClass("active"); }) } else { $('.btn-case-wrap').hover( function(){ $('.active-hide-list').toggleClass("active"); } ) } //--------------------------------------------- // SP閲覧時のみ電話番号にリンクを付ける //--------------------------------------------- var ua = navigator.userAgent; if(ua.indexOf('iPhone') > 0 || ua.indexOf('Android') > 0){ $('.tel-link').each(function(){ var str = $(this).text(); $(this).html($('').attr('href', 'tel:' + str.replace(/-/g, '')).append(str + '')); }); } //--------------------------------------------- // 外部リンクを別ウィンドウで開く //--------------------------------------------- $('a[href^=https]').not('[href*="'+location.hostname+'"]').attr('target', '_blank'); $('a[href^=http]').not('[href*="'+location.hostname+'"]').attr('target', '_blank'); //--------------------------------------------- // スムーズスクロール //--------------------------------------------- //#を含むリンクが対象 $('a[href^="#"]').click(function(){ var speed = 600, href = $(this).attr("href"), //href="#"ならページトップ(html)へ href="#"以外ならhrefの指定先へ target = $(href == "#" || href=="" ? 'html':href), position = target.offset().top; $('body,html').animate({scrollTop:position},speed,'swing'); return false; }); //--------------------------------------------- // pagetopボタン スクロールでフェードイン //--------------------------------------------- // 300pxスクロールしたらpagetopボタンを表示する var topBtn=$('#PageTop'); topBtn.hide(); $(window).scroll(function() { if($(this).scrollTop() > 300){ topBtn.fadeIn(); } else { topBtn.fadeOut(); } }); //--------------------------------------------- // スクロールで要素を表示 //--------------------------------------------- function showElementAnimation() { var element = document.getElementsByClassName('js-animation'); if(!element) return; // 要素がなかったら処理をキャンセル var showTiming = window.innerHeight > 768 ? 200 : 40; // 要素が出てくるタイミングはここで調整 var scrollY = window.pageYOffset; var windowH = window.innerHeight; for(var i=0;i elemY) { element[i].classList.add('is-show'); } else if(scrollY + windowH < elemY) { // 上にスクロールして再度非表示にする場合はこちらを記述 element[i].classList.remove('is-show'); } } } showElementAnimation(); window.addEventListener('scroll', showElementAnimation); }); //スクロールすると上部に固定させるための設定を関数でまとめる function FixedAnime() { var headerH =$('#Mainvisual').outerHeight(true) + $('header').outerHeight(true); var scroll = $(window).scrollTop(); if (scroll >= headerH){//headerの高さ以上になったら $('header').addClass('fixed');//fixedというクラス名を付与 }else{//それ以外は $('header').removeClass('fixed');//fixedというクラス名を除去 } } // 画面をスクロールをしたら動かしたい場合の記述 $(window).scroll(function () { FixedAnime();/* スクロール途中からヘッダーを出現させる関数を呼ぶ*/ });