一個平滑滾動JS庫:slimScroller.js

jopen 8年前發布 | 8K 次閱讀 JavaScript開發 slimScroller.js

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.baiduhome.net/lib/view/home/1451270216355

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!