Created
October 10, 2018 05:59
-
-
Save k-ish/c3582167ad50c7ab58d48b042eeb165f to your computer and use it in GitHub Desktop.
ヘッダー固定時のページ内リンクずれの位置修正
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function(){ | |
$('nav li a, .menu li a').click(function() { | |
var speed = 400; | |
var href= $(this).attr("href"); | |
var target = $(href == "#" || href == "" ? 'html' : href); | |
var headerHeight = 100; //固定ヘッダーの高さを指定 | |
var position = target.offset().top - headerHeight; //ターゲットの座標からヘッダの高さ分引く | |
$('body,html').animate({scrollTop:position}, speed, 'swing'); | |
return false; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment