Skip to content

aight8/smooth-scrollbar

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

smooth-scrollbar

npm npm devDependency Status npm Travis

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 --save

Via bower:

bower install smooth-scrollbar --save

Demo

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:

  1. As an element:

    <scrollbar>
        ...
    </scrollbar>
  2. As an attribute:

    <section scrollbar>
        ...
    </section>
  3. 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.
fricton Number 10 Scrolling fricton, a percentage value within (1, 100)

Confusing with the option field? Try editor 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

Instance

Work with RubaXa/Sortable

Details here.

Related

Todo

  • Overscroll effect.

Changelog

4.1.0

  • Reduce movement at container's edge.

4.0.0

  • Movement based scrolling algorithm.
  • Reduce options, simple is better :)

3.1.0

  • Use quadratic curve to perform scrollTo method.

3.0.0

  • New easing algorithm.
  • Dependency free!

License

MIT.

About

Customize scrollbar in modern browsers with smooth scrolling experience.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 89.0%
  • CSS 6.7%
  • HTML 4.3%