有り難いコードをコピペする 例1
https://atelier-light.com/blog/anchor_positioning/#toc3
jQuery(function () {
var headerHight = 100;
$('a[href^="#"]').click(function () {
var href = $(this).attr("href");
var target = $(href == "#" || href == "" ? "html" : href);
var position = target.offset().top - headerHight;
$("html, body").animate({ scrollTop: position }, 550, "swing");
return false;
});
});
有り難いコードをコピペする 例2
https://dezanari.com/jquery-anchor-header-fixed/
$(window).on('load', function() {
let headerHeight = $('.l-header').outerHeight();
let urlHash = location.hash;
if (urlHash) {
let position = $(urlHash).offset().top - headerHeight;
$('html, body').animate({ scrollTop: position }, 0);
}
});