Associate your duration with the pixels you need to move.
The duration of your code is locked at 500 . If I get the number of pixels that need to be moved in any direction and multiplied by a few milliseconds, you can get the set speed at which the page scrolls.
Replace this:
$('html,body').animate({scrollTop:$(this.hash).offset().top}, 500);
Wherein:
$('html,body').animate({scrollTop:$(this.hash).offset().top}, Math.abs(window.scrollY - $(this.hash).offset().top) * 10);
Change 10 above to increase or decrease the duration.
source share