jQuery scrollTo with pushState
— July 13, 2013
pushState:
$(document).ready(function() {
$('.nav-scroller > li > a').click(function(){
var myUri = $(this).attr('href');
$('html,body').animate({
scrollTop: $('#' + $(this).prop('class')).offset().top
}, 500);
history.pushState('', document.title, myUri);
return false;
});
});
- Every navigation anchor element needs a unique class name.
- The target elements needs the same unique class name but as id.
By @albertogg
Tweet