(function ($, _, util, obj) { $(function () { /*-------------------------------------------------*/ // デバイス判定 /*-------------------------------------------------*/ var isDevice = { 'mobile': true, 'run': function () { if ($(window).width() <= 1072) { //スマートフォン isDevice.mobile = true; } else { //PC isDevice.mobile = false; } } } isDevice.run(); $(window).on('load resize', function () { isDevice.run(); }); /*-------------------------------------------------*/ // スムーススクロール /*-------------------------------------------------*/ var smoothScroll = { 'adjust': function () { if (isDevice.mobile) { return 55; } else { return 84; } }, 'run': function (target) { if (isDevice.mobile) { headerMenu.close(); } target = $(target); if (target.length === 0) { var targetPosY = 0; } else { var targetPosY = target.offset().top; } $('html,body').animate({ scrollTop: targetPosY - smoothScroll.adjust() }, 800, 'swing'); } } $('[data-href]').on('click', function () { var target = $(this).attr('data-href'); smoothScroll.run(target); return false; }); /*-------------------------------------------------*/ // 追従メニュー01 /*-------------------------------------------------*/ var fixedHeader = { 'element': '', 'getHeader': function () { if (isDevice.mobile) { fixedHeader.element = $('.anchors-panel.only-sp'); } else { fixedHeader.element = $('.anchors-panel.only-pc'); } }, 'getTriggerPosY': function () { return $('.kv-panel').offset().top + $('.kv-panel').height(); }, 'fixed': function () { fixedHeader.element.addClass('isFixed'); $('.lead-panel').css({ 'margin-top': fixedHeader.element.outerHeight() }); }, 'removeFixed': function () { if (isDevice.mobile) { if (fixedHeader.element.hasClass('isFixed')) { headerMenu.close(); } } fixedHeader.element.removeClass('isFixed'); $('.lead-panel').css({ 'margin-top': 0 }); }, 'run': function (currentPosX, currentPosY) { fixedHeader.getHeader(); if (fixedHeader.getTriggerPosY() <= currentPosY) { if (!fixedHeader.element.hasClass('isFixed')) { fixedHeader.fixed(); $('.lead-panel').css({ 'margin-top': fixedHeader.element.outerHeight() }); } } else { if (fixedHeader.element.hasClass('isFixed')) { fixedHeader.removeFixed(); fixedHeader.element.removeAttr('style'); } } if (fixedHeader.element.hasClass('isFixed')) { fixedHeader.element.css({ 'transform': 'translateX(' + currentPosX * -1 + 'px)' }); } } } $(window).on('load scroll resize', function () { fixedHeader.run($(this).scrollLeft(), $(this).scrollTop()); }); /*-------------------------------------------------*/ /*-------------------------------------------------*/ var fixedHeader02 = { 'targetPosY': '', 'run': function (currentPosY) { var target = $('.anchors-voice-panel'); if (fixedHeader02.targetPosY <= currentPosY) { if (!target.hasClass('is-fixed')) { target.addClass('is-fixed'); } } else { if (target.hasClass('is-fixed')) { target.removeClass('is-fixed'); } } } } $(window).on('load', function () { fixedHeader02.targetPosY = $('.kv-panel').offset().top; }); $(window).on('load scroll resize', function () { if (isDevice.mobile) { fixedHeader02.run($(this).scrollTop()); } }); /*-------------------------------------------------*/ // 追従メニューの現在地 /*-------------------------------------------------*/ var checkActive = { 'targets': { 'element': [], 'posY': [] }, 'pushValues': function (screenHeight) { var anchors = $('.anchors-panel.only-pc .list-anchors ul a'); checkActive.targets.element = []; checkActive.targets.posY = []; anchors.each(function () { var target = $(this).data('href'); checkActive.targets.element.push(target); if (target !== '#') { checkActive.targets.posY.push($(target).offset().top - (screenHeight * 0.4)); } else { checkActive.targets.posY.push(0); } }); }, 'run': function (currentPosY) { var anchors = $('.anchors-panel.only-pc .list-anchors ul a'); for (var i = 0; i < checkActive.targets.posY.length; i++) { if (checkActive.targets.posY[i] <= currentPosY) { anchors.removeClass('active'); anchors.eq(i).addClass('active'); } } } } if (!isDevice.mobile) { $(window).on('load resize', function () { checkActive.pushValues($(this).height()); }); $(window).on('load scroll resize', function () { checkActive.run($(this).scrollTop()); }); } /*-------------------------------------------------*/ // justifyHeightを使用する /*-------------------------------------------------*/ var useJustifyHeight = { 'run': function () { var cards = $('.block-cards .card .card-intro'); cards.find('.title').css('height', 'auto'); if (!isDevice.mobile) { cards.find('.title').justifyHeight(3); } var features = $('.block-features .feature:not(.pattern-1)'); features.find('.lead').css('height', 'auto'); if (!isDevice.mobile) { features.find('.lead').justifyHeight(2); } } } $(window).on('load resize', function () { useJustifyHeight.run(); }); /*-------------------------------------------------*/ // カードを開く /*-------------------------------------------------*/ var cardToggle = { 'target': '', 'targetParent': '', 'isOpen': false, 'open': function () { $('.block-cards .card').removeClass('active'); cardToggle.targetParent.addClass('active'); cardToggle.isOpen = true; }, 'close': function () { cardToggle.targetParent.removeClass('active'); cardToggle.isOpen = false; }, 'run': function (target) { cardToggle.target = target; cardToggle.targetParent = cardToggle.target.parents('.card'); if (cardToggle.targetParent.hasClass('active')) { cardToggle.close(); } else { cardToggle.open(); } } } $('.block-cards .card').click(function (e) { e.stopPropagation(); }); $(document).on('click', function () { if (cardToggle.isOpen) { cardToggle.targetParent.removeClass('active'); } }); $('.block-cards .card a').on('click', function () { cardToggle.run($(this)); }); /*-------------------------------------------------*/ // SP版のヘッダーメニューを開く /*-------------------------------------------------*/ var scrollTopForMenu = 0; var headerMenu = { 'target': $('.anchors-panel.only-sp'), 'open': function () { if (!headerMenu.target.hasClass('isFixed')) { $('html,body').animate({ scrollTop: headerMenu.target.offset().top + 5 }, function () { headerMenu.target.addClass('isFixed'); }); } headerMenu.target.addClass('is-active'); $('.anchor-menu-bg').addClass('is-active'); }, 'close': function () { headerMenu.target.removeClass('is-active'); $('.anchor-menu-bg').removeClass('is-active'); }, 'run': function () { if ($('.anchors-panel.only-sp').hasClass('is-active')) { headerMenu.close(); } else { headerMenu.open(); } } } $('.anchors-panel.only-sp .anchor-menu').on('click', function () { headerMenu.run(); return false; }); }); })(BROTHER.lib.$, BROTHER.lib._, BROTHER.util, BROTHER.obj, BROTHER.ui);