Using vanilla JS, this is a very simple JavaScript smooth scroll script with ease in and out.
- Add
<script src="smoothscroll.js"></script>
inside the body tag. - Add a preferred
id="example"
to an element you'd like to scroll to. - Add
data-scrollto="example"
to an element you'd like to scroll from. For example, this could be<a data-scrollto="example">Link</a>
but you can link from other elements like span, div, or img too. - Ta-da!
If you are a really nice person, buy me a coffee.