Smoothly Scroll To Any Point Within The Document – slimScroller.js

Category: Animation , Javascript | December 27, 2019
Author: ameesme
Views Total: 190 views
Official Page: Go to website
Last Update: December 27, 2019
License: MIT

Preview:

Smoothly Scroll To Any Point Within The Document – slimScroller.js

Description:

slimScroller.js is an ultra-light JavaScript smooth scroll library that smoothly scrolls the page to any point within the document.

The point can be a CSS selector, an HTML element, or a position in pixels.

How to use it:

1. Load the slimScroller.js library in the document.

  • slimScroller.min.js (~0.5 kb): only supports CSS selector
  • slimScroller.full.min.js(~1 kb): supports any point
<script src="dist/slimScroller.min.js"></script>
<script src="dist/slimScroller.full.min.js"></script>

2. Smoothly scrolls to a specific point within the document.

// CSS selector
slimScroller.scroll("p");

// Scrolls down 200px
slimScroller.scroll(200);

// HTML element
slimScroller.scroll(document.querySelector(p#example));

3. Auto update the URL hash after scrolling.

window.addEventListener('load', function (){
  return slimScroller.bind(false, function (position){
    console.log('The current position is '+position);
  });
});

You Might Be Interested In:


Leave a Reply