(function( $ ) {
window.addEventListener('load', function() {
const threshold = 70;
let isSticky = false;
function checkSticky() {
const scrollTop = $(window).scrollTop();
if (scrollTop > threshold && !isSticky) {
$('#header').addClass('sticky');
isSticky = true;
} else if (scrollTop <= threshold && isSticky) {
$('#header').removeClass('sticky');
isSticky = false;
}
}
// ロード直後にも判定
checkSticky();
$(window).on('scroll', function() {
checkSticky();
});
});
})(jQuery);

コメント