0

Ok I'm new to this please don't judge me I looked around on the net and every video or suggestion seems over complicated as I managed my button to go to the top, I'm just missing the smooth animation. What am I missing form the below code?

 const myBtn = document.querySelector("#myBtn");
 myBtn.addEventListener("click", function() {
 window.scrollTo(0, 0);
 });
  • 1
    Does this answer your question? [smooth scroll to top](https://stackoverflow.com/questions/15935318/smooth-scroll-to-top) – blex Jul 04 '20 at 00:12

3 Answers3

0

If you're lazy, like I am then you can use this jQuery Plugin to get smooth scrolling to your link

Blomqen
  • 61
  • 1
  • 6
0

Try to use scrollIntoView()?

It can use smooth behavior.

ref: scrollIntoView

Alvin
  • 454
  • 3
  • 7
0

You don't need any plugins just use

window.scrollTo({
  top: 0,
  left: 0,
  behavior: 'smooth'
});