@awey/scroller
scroller
The best custom scroll bar. Can be nested.
I used it in my vue ui components library Admin-Ui. If you want to use it in vue or react, maybe you can look up the source of Admin-Ui Scroller
Attension: Scroller has been rewritten with typescript since version 2
install
Scroller can be installed by npm or yarn.
yarn install @awey/scroller
Or you can just install it as a script tag.
<script src="path-of-scroller/lib/scroller.iife.js"></script>
Useage
.custom-track-style {
background: red;
}
.custom-bar-style {
background: blue;
}
<div id="container">
<div style="width: 1200px; height: 1200px;"></div>
</div>
import Scroller from 'scroller'
import from 'scroller/lib/style.css'
const myScroller = new Scroller({
el: document.getElementById('container'),
direction: 'both',
offset: 4,
scaleable: true,
trackClassName: 'custom-track-style',
barClassName: 'custom-bar-style'
})
Note: All the children in container element should be element nodes (
nodeType=== 1). All the other types will be ignored.
Options
el: DOMElement, required, a container element which you want to made it a custom scrollbardirection: String, optional, determine which direction you would like to scroll. it support values below.both: default valuehorizontalverticalnone
offset: Number, optional, the space between scroll bar and element edge, max is 8 and min to 0, the default is 4scaleable: Boolean, optional, determine if the scroll bar width can enlarge or not when user hovering over the elementtrackClassName: String, optional, you can use it to customize the track stylebarClassName: String, optional, you can use it to customize the bar style
Methods
Scroller(options): Constructor, it returns an instance of scrollerscroller.setDirection(direction): Set scroll direction, it returns an instance of scrollerscroller.getScroll(): Return currentscrollTopandscrollLeftvaluescroller.onScroll(callback): Bind a scroll event listener to instance, the callback recieves anEventobject which is the native scroll event object. It returns current scroll instancescroller.offScroll(callback): Unbind a scroll event listener to instance, the callback recieves anEventobject which is the native scroll event object. Omitting callback will unbind all the scroll event listener. It returns current scroll instancescroller.scrollTo(position): Let scroller scroll to the specified position. It returns current scroll instanc.positionsis an object which contains keys belowscrollTop: OptionalscrollLeft: Optional
scroller.destroy(): Instance method, use it to destroy a scroller instance
Related Packages
vuebar
Vue directive for custom scrollbar that uses native scroll behavior. Lightweight...
279,585
634
@lionad/use-scrollbar-nuxt
Nuxt module for @lionad/use-scrollbar: auto-imports composables and injects scro...
470
14
Version History
| Version | Released | Vue | License |
|---|---|---|---|
| 2.3.2 | ^3.2.37 | MIT | |
| 2.3.1 | ^3.2.37 | MIT | |
| 2.3.0 | ^3.2.37 | MIT | |
| 2.2.1 | ^3.2.37 | MIT | |
| 2.2.0 | ^3.2.37 | MIT | |
| 2.1.2 | ^3.2.37 | MIT | |
| 2.1.1 | ^3.2.37 | MIT | |
| 2.1.0 | ^3.2.37 | MIT | |
| 2.0.5 | ^3.2.37 | MIT | |
| 2.0.4 | ^3.2.37 | MIT | |
| 2.0.3 | ^3.2.37 | MIT | |
| 2.0.2 | ^3.2.37 | MIT | |
| 2.0.1 | ^3.2.37 | MIT | |
| 2.0.0 | ^3.2.37 | MIT | |
| 1.2.9 | GPL-3.0-or-later | ||
| 1.2.8 | GPL-3.0-or-later | ||
| 1.2.7 | GPL-3.0-or-later | ||
| 1.2.5 | GPL-3.0-or-later | ||
| 1.2.4 | GPL-3.0-or-later | ||
| 1.2.3 | GPL-3.0-or-later | ||
| 1.2.2 | GPL-3.0-or-later | ||
| 1.2.1 | GPL-3.0-or-later | ||
| 1.2.0 | GPL-3.0-or-later | ||
| 1.1.24 | GPL-3.0-or-later | ||
| 1.1.23 | GPL-3.0-or-later | ||
| 1.1.22 | GPL-3.0-or-later | ||
| 1.1.21 | GPL-3.0-or-later | ||
| 1.1.20 | GPL-3.0-or-later | ||
| 1.1.19 | GPL-3.0-or-later | ||
| 1.1.18 | GPL-3.0-or-later |
Showing the latest 30 of 63. See every release on npm