Created
January 14, 2021 15:42
-
-
Save jmarreros/eca1e315c6ce72e9c26b769f2a723bb2 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( $ ) { | |
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