adjacent - yagisawatakuya/Wiki GitHub Wiki
参考:https://qiita.com/noqua/items/b9c9cd8f2243e91143c8
$(function() {
$(window).load(setColHeight);
$(window).resize(setColHeight);
var $itemWrap = $('.clinic_info'); // 全体の要素
function setColHeight(){
var w = $(window).width();
if(w >= 736) { // ブレイクポイントを指定。
$itemWrap.each( function (){
$(this).find('.js_colHeight:even').each( function (){
var $itemBox = $(this).find('.box_img_txt');
var $itemTtl = $(this).find('.ttl_lv3_a');
var $adjacentItemBox = $('+.js_colHeight .box_img_txt', this);
var $adjacentItemTtl = $('+.js_colHeight .ttl_lv3_a', this);
var $thisHeight = $itemBox.height();
var $evenHeight = $adjacentItemBox.height();
var $thisHeightTtl = $itemTtl.height();
var $evenHeightTtl = $adjacentItemTtl.height();
//偶数・奇数要素の高さを比較し、高い方に合わせる
if($thisHeight > $evenHeight) {
$adjacentItemBox.css('height',$thisHeight +'px');
$itemBox.css('height',$thisHeight +'px');
} else {
$adjacentItemBox.css('height',$evenHeight +'px');
$itemBox.css('height',$evenHeight +'px');
}
if($thisHeightTtl > $evenHeightTtl) {
$adjacentItemTtl.css('height',$thisHeightTtl +'px');
$itemTtl.css('height',$thisHeightTtl +'px');
} else {
$adjacentItemTtl.css('height',$evenHeightTtl +'px');
$itemTtl.css('height',$evenHeightTtl +'px');
}
});
});
} else {
$itemWrap.find('.box_img_txt').css('height','');
$itemWrap.find('.ttl_lv3_a').css('height','');
}
}
});