Blog de tfe, Perl, Web et Libre...?

Smoothscroller javascript library

PubliƩ le 18/06/2016 dans javascript

I just built a simple library for a work project that allows a smooth scroll effect based on the scroll position.
Why? Because all the lib i found allowed me to trigger an animation based on the scroll position, but without the smooth effect.

You can check a really simple demo page to see it live.

To use it, all you need to do get the smoothscroller.js file available on the Repository, and use it:
Then create a callback: a function that will receive the html item, scroll position and percent of the animation complete (based on the starting and end positions given).
function item_animation(item, scroll_position , percent_complete)
       = (percent_complete*100)+'%';
And finally, add tell the library what to do:
smoothscroller.add(start_position, end_position, your_callback.bind(this,the_html_item));

Download Smoothscroller