// JavaScript Document $(function(){ // ページ内リンクの処理 //$('.siteHeader').addClass('fixed'); // var _headerHeight = $('.siteHeader').height(); var _headerHeight ; var speed = 500; $('a[href^="#"]' + 'a:not([role *= "tab"])' +'a:not([data-slide="prev"])' + 'a:not([data-slide="next"])').click(function(){ var href= $(this).attr("href"); var target = $(href == "#" || href == "" ? 'html' : href); //var position = target.offset().top - _headerHeight; ヘッダを固定している場合のページ内リンクのズレ補正 var position = target.offset().top; $('html, body').animate({scrollTop:position}, speed, "swing"); return true; }); // ページ外リンクの処理 $(window).on('load', function() { var hash = location.hash; if(!hash) { return; } var target_offset = $(hash).offset(); var target_top = Math.ceil(target_offset.top - _headerHeight); $('html, body').animate({scrollTop:target_top}, 100); }); });