(function($){ $("body a[href*=#]:not(.fancybox):not(.fancybox-inline)").click(function(){ var Hash = $(this.hash); if( this.pathname === location.pathname ) { var HashOffset = $(Hash).offset().top - $('.recipe_menu').outerHeight() - 20; if( Hash.selector.indexOf("#page") >= 0 ) { // #topの時だけずらさない HashOffset = $(Hash).offset().top; } $("html,body").stop().animate({ scrollTop: HashOffset }, 1000); return false; } }); $(window).load(function(){ var Hash = $(location.hash); if( Hash.length > 0 ) { var HashOffset = $(Hash).offset().top - $('.recipe_menu').outerHeight() - 20; if( Hash.selector.indexOf("#page") >= 0 ) { // #topの時だけずらさない HashOffset = $(Hash).offset().top; } $("html,body").stop().animate({ scrollTop: HashOffset }, 1000); return false; } }); })(jQuery);