//////////////////////////////////////////////////////////////////////////////// // // 関数実行 // //////////////////////////////////////////////////////////////////////////////// $(function () { slideToggleFunc(); hoverFunc(); switchImg(); resizeImg(); MatchHeightCtrl(); }); //////////////////////////////////////////////////////////////////////////////// // // 関数 // //////////////////////////////////////////////////////////////////////////////// /******************************************************************************/ // slideToggleFunc /******************************************************************************/ function slideToggleFunc() { var accordion = $(".accordion"); accordion.each(function () { var noTargetAccordion = $(this).siblings(accordion); $(this).find(".js-toggle-btn").click(function() { if($(this).hasClass('open')){ $(this).prev(".photoArea ul").slideDown(); noTargetAccordion.find(".photoArea ul").slideUp(); noTargetAccordion.find(".js-toggle-btn").removeClass("open"); $(this).text('閉じる'); $(this).removeClass('open').addClass('close'); } else if($(this).hasClass('close')){ $(this).prev(".photoArea ul").slideUp(); noTargetAccordion.find(".photoArea ul").slideUp(); noTargetAccordion.find(".js-toggle-btn").removeClass("open"); $(this).text('もっと見る'); $(this).removeClass('close').addClass('open'); } }); }); } /******************************************************************************/ // hoverFunc /******************************************************************************/ function hoverFunc() { if ($(window).width() > 641) { $('.js-hover').each(function(){ var src_off = $(this).find('img').attr('src'); var src_on = src_off.replace('_off','_on'); $('').attr('src',src_on); $(this).hover(function(){ $(this).find('img').attr('src',src_on); },function(){ $(this).find('img').attr('src',src_off); }); }); } } /******************************************************************************/ // windowサイズによって画像切り替え /******************************************************************************/ function switchImg() { var pcName = '_pc', spName = '_sp', replaceWidth = 641; $('.js-switch').each(function(){ var $this = $(this); function imgSize(){ var windowWidth = parseInt($(window).width()); if(windowWidth >= replaceWidth) { $this.attr('src',$this.attr('src').replace(spName,pcName)); } else if(windowWidth < replaceWidth) { $this.attr('src',$this.attr('src').replace(pcName,spName)); } } $(window).resize(function(){imgSize();}); imgSize(); }); } /******************************************************************************/ // 縦長画像にclass追加 /******************************************************************************/ function resizeImg() { $('.photoArea figcaption li').each(function(){ var imgWidth = $(this).find('img').width(); var imgHeight = $(this).find('img').height(); aspectRatio = imgWidth / imgHeight if(aspectRatio >= 1){ return; }else{ $(this).find('img').addClass('resize'); } }); } /******************************************************************************/ // 近接する要素の高さを揃える /******************************************************************************/ function MatchHeightCtrl(){ $('.js-matchHeight').matchHeight(); }