(function($){ // loading window.onload = function() { const loading = document.getElementById('loading'); if ( loading && loading.classList ) { loading.classList.add('is-loaded'); } } $(function() { const $win = $(window); const $header = $('#header'); // ヘッダ // ブレイクポイント let is_pc = true; let is_tab = false; let is_sp = false; // ボタンを変化させる const $contact_wrap = $('#contact_area_wrap'); const $contact_area = $('#contact_area'); const $contact_fixed = $('#contact_area--fixed'); const contact_classes = { open: 'js-open', close: 'js-close' }; $win.on('load resize scroll', function() { is_sp = window.matchMedia('(max-width: 480px)').matches; is_tab = ( ! is_sp && window.matchMedia('(max-width: 768px)').matches ); is_pc = ( ! is_sp && ! is_tab ); if ( ! is_pc ) { $contact_fixed.hide(); } else { $contact_fixed.show(); const contact_top = $contact_wrap.offset().top; if ( contact_top - ($win.scrollTop() + $win.height()) < 100 ) { $contact_area .addClass(contact_classes.open) .removeClass(contact_classes.close); $contact_fixed .addClass(contact_classes.close) .removeClass(contact_classes.open); } else { $contact_area .addClass(contact_classes.close) .removeClass(contact_classes.open); $contact_fixed .addClass(contact_classes.open) .removeClass(contact_classes.close); } } }); // グロナビ $('.l-gnavi_list') .on('mouseover focusin',function() { $(this).addClass('js-active'); }) .on('mouseout focusout',function() { $(this).removeClass('js-active'); }); $win.on('load resize', function() { $('.l-dropdown_lists').each(function(){ const h = this.scrollHeight; this.style.setProperty('--max-height', h + 'px'); }) }); /** * ページ内リンク時、スクロール位置を固定ヘッダを考慮したものに補正 * @param delay 補正が発動する時間間隔(ミリ秒)。デフォルト1秒。 * @param flagment 移動先のフラグメント(「#」から始まる文字列)。指定しない場合、URLから自動取得 */ const fix_in_page_link = function( delay, flagment ) { const asobi = 30; // 余分 if ( ! flagment ) { if ( location.hash ) { flagment = location.hash; } else { return; // 何もせず終了 } } const $elm = $(flagment); if ( ! $elm.length ) { return; // 何もせず終了 } if ( ! delay ) { delay = 1000; // デフォルト1秒後 } const pos = $elm.offset().top - $header.height() - asobi; if ( pos > 0 ) { setTimeout(function() { $('html, body').animate( { scrollTop: pos }, 200 ); }, delay); } }; fix_in_page_link(); // Smooth Scroll var smooth_patterns = [ new RegExp( '^#' ), new RegExp( '^' + location.href.replace( location.hash, '' ) + '#' ), new RegExp( '^' + location.pathname + '#' ), ]; $('a[href*="#"]').click(function(){ var href = $(this).attr('href'); var flg = false; for( var i=0,len=smooth_patterns.length; i 0 ) { $('html, body').animate( {scrollTop: t.offset().top}, 400, 'swing', function() { fix_in_page_link( 10 ) } ); location.hash = h; return false; } return true; } } }); // スクロールで順次表示させる const show_on_scroll = function() { // アニメーションについては、下記 class に、CSSにて適用する。 const classes = { // 適用するエレメントのclass名 element: 'c-show_on_scroll', // スクロール到達時に付与するclass名 animation: 'c-show_on_scroll--animation' }; $win.on('load scroll', function() { const pos = $win.scrollTop(); const wh = $win.height(); $('.' + classes.element).each(function() { const $this = $(this); if ( ! $this.hasClass( classes.animation ) ) { const ofs = $this.offset().top; if ( pos > ofs - wh + (wh / 5) ) { // data-delay が指定されていたら、その分遅らせる const delay = $this.attr('data-delay'); if ( delay ) { $this.css({ 'animation-delay': delay }); } const duration = $this.attr('data-duration'); if ( duration ) { $this.css({ 'animation-duration': duration }); } let anim_class = $this.attr('data-animation-class'); if ( ! anim_class ) { anim_class = classes.animation; } $this.addClass( anim_class ); } } }); }); }; show_on_scroll(); // 言語切り替えボタン const $lang_select = $('#lang_select'); const $lang_label = $lang_select.find('label'); const $lang_input = $('#lang_select_checkbox'); const $menu = $('.p-lang_select__menu'); $lang_label.on('focus', function(ev) { $menu.find('a').eq(0).focus(); }); $lang_select.on('mouseover focusin', function() { if ( ! $lang_input.is(':checked') ) { $lang_select.addClass('is-open'); } }); $lang_select.on('mouseleave blur', function() { $lang_select.removeClass('is-open'); $lang_input.prop('checked', false); }); $lang_input.on('change init',function() { const $this = $(this); if ( $this.is(':checked') ) { $lang_select.addClass('is-open'); } else { $lang_select.removeClass('is-open'); } }).trigger('init'); }); })( jQuery );