jQuery
1$(function () { 2// スムーススクロール 3 // ナビゲーションをクリック 4 $("a[href^=#]:not([href=#])").click(function () { 5 // 移動先のコンテンツの位置を取得 6 var target = $($(this).attr("href")).offset().top; 7 8 // 70px減らす 9 target -= 70; 10 11 // コンテンツへスクロール 12 $("html, body").animate({ 13 scrollTop: target 14 }, 500); 15 16 return false; 17 }); 18});
回答2件