Skip to content

Instantly share code, notes, and snippets.

@jmarreros
Created January 14, 2021 15:42
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 jmarreros/eca1e315c6ce72e9c26b769f2a723bb2 to your computer and use it in GitHub Desktop.
Save jmarreros/eca1e315c6ce72e9c26b769f2a723bb2 to your computer and use it in GitHub Desktop.
(function( $ ) {
const marginTop = 170; // puedes cambiar el margen
const currentClasses = 'current-menu-item current_page_item';
if ( ! window.location.hash ){
$('li').removeClass(currentClasses);
$('li:first-child').addClass(currentClasses);
}
$('li a[href*="#"]').click(function(event) {
const link = this;
let target = $(link.hash);
event.preventDefault();
target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
$('html, body').animate({
scrollTop: target.offset().top - marginTop
}, 1000, function() {
$('li').removeClass(currentClasses);
$(link).parent().addClass(currentClasses);
});
});
})( jQuery );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment