JavaScript Library For Smooth Page Scrolling Effect – smoothScroll

Category: Animation , Javascript | July 20, 2018
Authoralicelieutier
Last UpdateJuly 20, 2018
LicenseMIT
Views1,944 views
JavaScript Library For Smooth Page Scrolling Effect – smoothScroll

smoothScroll is a super tiny (~2kb) JavaScript library which enables your webpage scrolling to a specified position within the document.

How to use it:

Include the smoothScroll JavaScrip library in your document.

<script src="smoothscroll.js"></script>

Create an anchor link pointing to the specified position of your web page. That’s it. smoothScroll will look for all the internal links in the documents and attach the smooth scroll function.

<a href="#context">Anchor Link</a>
...
<h2 id="context">Target element</h2>

Parameters.

// target: a HTMLElement Object from your document that you want to scroll to, or a numeric position on the page
// duration: the total duration of the scroll
// callback: a function to be executed when the scrolling is over
window.smoothScroll(target, duration, callback)

Changelog:

v0.4.0 (07/20/2018)

  • Makes it possible to preventDefault() on link click event

You Might Be Interested In:


Leave a Reply