// breakPoint
//=====================================================
$windowWidth = window.innerWidth;
$breakPointA = 768;
$breakPointB = 1100;
isSP = ($windowWidth < $breakPointA);
isTB = ($windowWidth <= $breakPointB) && ($windowWidth > $breakPointA);
isPC = ($windowWidth > $breakPointB);
isSPTB = ($windowWidth < $breakPointB);
//汎用 スムーズスクロール
const smoothScrollTrigger = document.querySelectorAll('a[href^="#"]');
for (let i = 0; i < smoothScrollTrigger.length; i++) {
smoothScrollTrigger[i].addEventListener('click', (e) => {
e.preventDefault();
let href = smoothScrollTrigger[i].getAttribute('href');
let targetElement = document.getElementById(href.replace('#', ''));
const rect = targetElement.getBoundingClientRect().top;
const offset = window.pageYOffset;
const gapSPTB = 65;
const gapPC = 0;
const targetSPTB = rect + offset - gapSPTB;
const targetPC = rect + offset - gapPC;
if(isSPTB) {
window.scrollTo({
top: targetSPTB,
behavior: 'smooth',
});
}
if(isPC) {
window.scrollTo({
top: targetPC,
behavior: 'smooth',
});
}
});
}
コメントを残す