I am using this script to scroll to the element ID
$('.smoothscroll').on('click',function(e) {
if (/#/.test(this.href)) {
if (document.location.pathname == "/") {
e.preventDefault();
var offset = headerHeight;
var target = this.hash;
$('html, body').stop().animate({
'scrollTop': $(target).offset().top - offset
}, 500, 'swing', function() {
// window.location.hash = target;
});
};
};
});
but if I uncomment window.location.hash = target;
the page jumps after the scroll animation.
How can I scroll to the element and update the URL without the jump?