1

i have used onclick event

    scrolltoTop= async () => {
        window.scrollTo(0,0)
     }

but it takes more time to go top so how to go top dyrect using javascript, and if it is not support than how to fast scroll?

ketan
  • 163
  • 1
  • 9
  • Does this answer your question? [Scroll to the top of the page using JavaScript?](https://stackoverflow.com/questions/1144805/scroll-to-the-top-of-the-page-using-javascript) – PatricNox Nov 19 '21 at 12:35

1 Answers1

0

Instead of window.scrollTo(xCoord, yCoord); you can use scrollIntoView() like so:

<html>
  <body>
   <div id="top"></div>
   .....
  </body>
</html>

<script>
  document.getElementById("top").scrollIntoView();
</script>
PatricNox
  • 3,306
  • 1
  • 17
  • 25