Last active
August 29, 2015 14:14
-
-
Save rimenes/3aeb1c6876981c81d6a1 to your computer and use it in GitHub Desktop.
Scroll to div + pushState
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
var base_url = 'http://localhost' | |
$('.menu a').on('click', function(event) { | |
event.preventDefault(); | |
var path = this.attr("href"); | |
history.pushState("", "", path); | |
path = path.replace(base_url, ''); | |
path = path.replace('/', ''); | |
path = path.replace('#', ''); | |
$('html,body').animate({scrollTop: ($('#' + path).offset().top)}, 1000); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment