Is there a smooth scroll between anchors on a pure JS?

Interested in is there a script for smooth scrolling on pure JS, website do without using jQuery
June 8th 19 at 19:28
4 answers
June 8th 19 at 19:30
Solution
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 -->

If you know about it
Thank you very much) - addison_Dickens commented on June 8th 19 at 19:33
June 8th 19 at 19:32
The animation is anything in pure JS https://learn.javascript.ru/js-animation
June 8th 19 at 19:34
For modern browsers to invent anything not necessary, everything is already there.
element.scrollIntoView({ behavior: 'smooth' })
For the rest, you can temporarily of apoliticality.
June 8th 19 at 19:36

Find more questions by tags JavaScript