Skip to content

Instantly share code, notes, and snippets.

@johnnya23
Last active January 5, 2022 12:58
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 johnnya23/3fae649aa7a1e5f23bb0a25e55154cc4 to your computer and use it in GitHub Desktop.
Save johnnya23/3fae649aa7a1e5f23bb0a25e55154cc4 to your computer and use it in GitHub Desktop.
Scrolling Local Menu in navbar
jQuery(document).ready(function($) {
var win_split = window.location.href.split('#');
function gotoid(id) {
$('html,body').animate({
scrollTop: $("#" + id).offset().top - 150
}, 500);
}
if (win_split.length > 1) {
gotoid(win_split[1]);
}
$('.nav').find('a[href*=#]').not('a[href="#"]').on("click", function(e) {
var menu_href = $(this).attr("href");
split = menu_href.split('#');
if (win_split[0] == split[0]) {
//its on this page
e.preventDefault();
gotoid(split[1]);
//close the mobiel menu
$('body').removeClass('open');
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment