一个平滑滚动JS库:slimScroller.js

jopen 8年前

SlimScroller.js 是平滑滚动,小于 300 字节 (gzipped),无其他依赖。

A slim smooth-scrolling script under 300 bytes (gzipped), with no other dependencies (No jQuery).

Two versions

SlimScroller Base

540  bytes gzipped  1010 bytes uncompressed

The base includes support for four types of scroll-targets:

  • Position in pixels ( eg.slimScroller.scroll(200))
  • CSS selector ( eg.slimScroller.scroll("p:first-of-type"))
  • Direct JavaScript HTML-element ( eg.slimScroller.scroll(document.querySelector(p#hi)))

Hashtags

By executingslimScroller.bind()when the dom finishes loading, SlimScroller will also animate same-page hashtag-scrolling in anchor tags.

SlimScroller Small

282 bytes gzipped  464 bytes uncompressed

The small version includes support for one type of scroll-target:

  • CSS selector ( eg.slimScroller.scroll("p:first-of-type"))

How to scroll

Just use theslimScroller.scroll-function with the following parameters.

  • RequiredScroll-target according to SlimScroller-version
  • OptionalDuration inms
  • OptionalSwitch to horizontal-scrolling inboolean
  • OptionalCallback-function with resulting scroll-position as parameter

NPM

Yes. Usenpm install slimscroller.

项目主页:http://www.open-open.com/lib/view/home/1451270216355