//========================================================
// アニメーション
//========================================================
$(function () {
setTimeout(function () {
$('.first-view').addClass('is-animation');
},1000);
});
$(window).on('load scroll', function () {
isAnimation();
});
function isAnimation() {
$('.js-animation').each(function () {
var win_scroll = $(window).scrollTop();
var win_height = $(window).height();
var scroll_pos = win_scroll + win_height;
if ($(this).offset().top < scroll_pos) {
$(this).addClass('is-animation');
}
});
}
//========================================================
// SVG icon
//========================================================
// サークルリンクアイコン
$(function () {
var svgIcon = '';
$('.btn-lf-a').prepend(svgIcon);
});
// PDFアイコン
$(function () {
var svgIcon = '';
$('.btn-lf-b').prepend(svgIcon);
});
// movアイコン
$(function () {
var svgIcon = '';
$('.btn-lf-c').prepend(svgIcon);
});
//========================================================
// 高さ揃えスクリプト
//========================================================
// ウィンドウ幅の判定
function checkDeviceType() {
var width = window.innerWidth;
if (width > 767) {
return 'pc';
} else if (width > 1) {
return 'sp'
} else {
return 'zero';
}
}
// 現在の画面で定義したブレイクポイントと一致するか判定
function matchHtmlDataBreakpoint(device, breakpoint) {
if (breakpoint === 'zero') {
if (device === 'zero') {
return false;
} else {
return true;
}
} else if (breakpoint === 'sp') {
if (device === 'zero' || device === 'sp') {
return false;
} else {
return true;
}
}
}
// htmlのData属性からブレイクポイントを取得
function getHtmlDataBreakpoint(num) {
var breakpoint = $('#js-align-height-breakpoint-sp' + num);
if (!breakpoint.length) {
return 'sp';
}
return 'zero';
}
// 高さをそろえたい要素のグループを取得
function getClassList() {
var elements = $('[class*="js-align-height-box"]'),
classList = [],
className;
elements.each(function (index, element) {
className = element.getAttribute('class').match(/js-align-height-box[0-9]+/);
if (!className) {
return;
}
if (classList.indexOf('.' + className[0]) >= 0) {
return;
} else {
classList.push('.' + className[0]);
}
});
return classList;
}
// 高さ調整スクリプト
// 取得した中で一番高い高さを付与する
function matchHeight() {
var elementsGroup = getClassList(), // 高さを揃えたいグループのクラスを取得する
maxHeight = 0, //一番高さのある要素の高さ
boxHeight = 0, //要素の高さ
device = checkDeviceType(), //sp
breakpoint, //高さを揃える際のブレイクポイント
needClearMaxHeight; //高さのクリアが必要な
elementsGroup.forEach(function (elements) {
$(elements).css('height', 'auto');
if (elements.match(/[0-9]+/) != null) {
breakpoint = getHtmlDataBreakpoint(elements.match(/[0-9]+/)[0]);
} else {
return;
}
needClearMaxHeight = matchHtmlDataBreakpoint(device, breakpoint);
if (!needClearMaxHeight) {
return;
}
// 高さの比較
$(elements).each(function (index, element) {
boxHeight = $(element).outerHeight();
if (index === 0) {
maxHeight = boxHeight;
} else if (maxHeight < boxHeight) {
maxHeight = boxHeight;
}
});
// 要素にmaxHeightを指定
$(elements).css('height', maxHeight + 'px');
});
};
window.addEventListener('load', function () {
matchHeight();
});
window.addEventListener('resize', function () {
setTimeout(function () {
matchHeight();
//ウィンドウサイズがリサイズされたときに、高さ調整スクリプトを起動する
}, 500);
});