Skip to content

Instantly share code, notes, and snippets.

@MrAMS
Last active February 11, 2019 04:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MrAMS/575a3b3ea1cfba1545105e582db3faf6 to your computer and use it in GitHub Desktop.
Save MrAMS/575a3b3ea1cfba1545105e582db3faf6 to your computer and use it in GitHub Desktop.
完美解决Bootstrap4 导航栏 fixed-top 后,锚点定位时遮挡问题

利用锚点改变事件onhashchange详见使用jQuery的scrollTop向前滚回导航栏的高度(比如我的100个像素) HTML:

<body onhashchange="fix_the_nav();">
</body>

js:

function fix_the_nav() {
    if(window.location.hash){
            var target = $(location.hash);
            $("body,html").scrollTop(target.offset().top-100); # my nav size is 100px
    }
}

Done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment