Package Exports
- smooth-scrollbar
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (smooth-scrollbar) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
smooth-scrollbar
Customize scrollbar in modern browsers with smooth scrolling experience.
Browser Compatibility
| Browser | Version |
|---|---|
| IE | 10+ |
| Chrome | 22+ |
| Firefox | 16+ |
| Safari | 8+ |
| Android Browser | 4+ |
| Chrome for Android | 32+ |
| iOS Safari | 7+ |
Install
Via npm:
npm install smooth-scrollbar --saveVia bower:
bower install smooth-scrollbar --saveDemo
http://idiotwu.github.io/smooth-scrollbar/
Why is native scrolling slow?
As is explained in this article, browser repaint every frame in scrolling. Less painting is better.
To avoid repainting, I use translate3d in scroll content to create composite layers and force hardware accelerating.
Usage
Smooth scrollbar is defined as an UMD module which named Scrollbar, you can use any loader to load it:
import Scrollbar from 'smooth-scrollbar';Or get it from window object:
const { Scrollbar } = window;Don't forget to include the stylesheet in your page:
<link rel="stylesheet" href="dist/smooth-scrollbar.css">Here're three ways to tell the plugin which element should be a smooth scrollbar:
As an element:
<scrollbar> ... </scrollbar>
As an attribute:
<section scrollbar> ... </section>
As a data attribute
<section data-scrollbar> ... </section>
Then init all scrollbars:
Scrollbar.initAll(options);Or you can call Scrollbar.init(elem, options) to manually init the scrollbar.
Available Options for Scrollbar
| parameter | type | default | description |
|---|---|---|---|
| speed | Number | 1 | Scrolling speed scale. |
| friction | Number | 10 | Scrolling friction, a percentage value within (1, 100). |
| thumbMinSize | Number | 20 | Minimal size for scrollbar thumb. |
| continuousScrolling | Boolean | false | Whether allow upper scrollable content to continue scrolling when current scrollbar reaches edge. |
| ignoreEvents | Array | [] | A list of events names that are ignored, regex rules are supported. Details here. |
Confusing with the option field? Try edit tool here!
DOM Structure
Following is the DOM structure that Scrollbar generated:
<scrollbar>
<article class="scroll-content">
your contents here...
</article>
<aside class="scrollbar-track scrollbar-track-x">
<div class="scrollbar-thumb scrollbar-thumb-x"></div>
</aside>
<aside class="scrollbar-track scrollbar-track-y">
<div class="scrollbar-thumb scrollbar-thumb-y"></div>
</aside>
</scrollbar>APIs
Scrollbar
- Scrollbar.init( element, [options] )
- Scrollbar.initAll( [options] )
- Scrollbar.has( element )
- Scrollbar.get( element )
- Scrollbar.getAll()
- Scrollbar.destroy( element )
- Scrollbar.destroyAll()
Instance
Properties
Methods
- instance#update( [async] )
- instance#getSize()
- instance#setPosition( x, y, [withoutCallbacks] )
- instance#scrollTo( x, y, [duration], [callback] )
- instance#scrollIntoView( elem, [options] )
- instance#isVisible( elem )
- instance#addListener( fn )
- instance#removeListener( fn )
- instance#infiniteScroll( callback, [threshold] )
- [instance#clearMovement()]
- [instance#stop()]
- instance#destroy()
- instance#getContentElem()
- instance#showTrack( direction )
- instance#hideTrack()
Work with RubaXa/Sortable
Details here.
Related
Todo
- Overscroll effect.
License
MIT.