var linkNav = document.querySelectorAll('[href^="#"]'), //select all the links to the anchor on the page
V = 1; // speed, can have a fractional value through the point (the smaller the value, the greater the speed)
for (var i = 0; i < linkNav.length; i++) {
linkNav[i].addEventListener('click', function(e) { //on clicking on link
e.preventDefault(); //cancel default behavior
var w = window.pageYOffset, // produce the scrolling scrolling
hash = this.href.replace(/[^#]*(.*)/, '$1'); // the id of the element to which you want to go
t = document.querySelector(hash).getBoundingClientRect().top, // offset from the browser window id
start = null;
requestAnimationFrame(step); // read more about feature animation [developer.mozilla.org]
function step(time) {
if (start === null) start = time;
var progress = time - start,
r = (t < 0 ? Math.max(w - progress/V, w + t) : Math.min(w + progress/V, w + t));
window.scrollTo(0,r);
if (r != w + t) {
requestAnimationFrame(step)
} else {
location.hash = hash // URL with hash
}
}
}, false);
}
<a id="scroll" href="#one">day</a> <!-- link, click on that scroll to the anchor -->
<a id="one" name="one"></a> <!-- the anchor located at an arbitrary position on the page -->
element.scrollIntoView({ behavior: 'smooth' })
Find more questions by tags JavaScript