Smooth scrolling to elements with JavaScript (no jQuery)

Smooth scrolling to elements with JavaScript (no jQuery)

Here’s a quick snippet of JavaScript to scroll to elements on your webpage smoothly.

This example is in vanilla JavaScript and does not require jQuery to work correctly.

Let’s say you have a page with similar markup to the snippet below.

When a user clicks your links, you would like the browser to scroll smoothly to the start of the element. However, you don’t wish to use jQuery. Fortunately for us, we can achieve this using vanilla JavaScript and the scrollIntoView method.

Check out the JavaScript below to achieve this ,making note of the comments.

I hope this helps and please feel free to share and follow us on Twitter for more.





Leave a Reply

Your email address will not be published. Required fields are marked *