UNPKG

6.95 kBMarkdownView Raw
1# Angular Perfect Scrollbar
2
3<a href="https://badge.fury.io/js/ngx-perfect-scrollbar"><img src="https://badge.fury.io/js/ngx-perfect-scrollbar.svg" align="right" alt="npm version" height="18"></a>
4
5This is an Angular wrapper library for the [Perfect Scrollbar](https://utatti.github.io/perfect-scrollbar/). To use this library you should get familiar with the Perfect Scrollbar documentation as well since this documentation only explains details specific to this wrapper.
6
7This documentation is for the latest 5/6.x.x version which requires Angular 5 or newer. For Angular 4 you need to use the latest 4.x.x version. Documentation for the 4.x.x can be found from <a href="https://github.com/zefoy/ngx-perfect-scrollbar/tree/4.x.x/">here</a>.
8
9### Quick links
10
11[Example application](https://zefoy.github.io/ngx-perfect-scrollbar/)
12 |
13[StackBlitz example](https://stackblitz.com/github/zefoy/ngx-perfect-scrollbar/tree/master)
14 |
15[Perfect Scrollbar documentation](https://github.com/utatti/perfect-scrollbar/)
16
17### Building the library
18
19```bash
20npm install
21npm run build
22```
23
24### Running the example
25
26```bash
27npm install
28npm run start
29```
30
31### Installing and usage
32
33```bash
34npm install ngx-perfect-scrollbar --save
35```
36
37##### Load the module for your app (with global configuration):
38
39Providing the global configuration is optional and when used you should only provide the configuration in your root module.
40
41```javascript
42import { PerfectScrollbarModule } from 'ngx-perfect-scrollbar';
43import { PERFECT_SCROLLBAR_CONFIG } from 'ngx-perfect-scrollbar';
44import { PerfectScrollbarConfigInterface } from 'ngx-perfect-scrollbar';
45
46const DEFAULT_PERFECT_SCROLLBAR_CONFIG: PerfectScrollbarConfigInterface = {
47 suppressScrollX: true
48};
49
50@NgModule({
51 ...
52 imports: [
53 ...
54 PerfectScrollbarModule
55 ],
56 providers: [
57 {
58 provide: PERFECT_SCROLLBAR_CONFIG,
59 useValue: DEFAULT_PERFECT_SCROLLBAR_CONFIG
60 }
61 ]
62})
63```
64
65##### Use it in your HTML template (with custom configuration):
66
67This library provides two ways to create a Perfect Scrollbar element, a component and a directive. Component tries to make the usage as simple as possible and the directive is meant for more custom / advanced use cases.
68
69The scroll area always needs some fixed height to work. The default styles uses 100% as the height value so the parent needs to have fixed height or you need to set it via CSS styles. Otherwise the height keeps growing and you won't get the scrollbars.
70
71**COMPONENT USAGE**
72
73Simply replace the element that would ordinarily be passed to `PerfectScrollbar` with the perfect-scollbar component.
74
75```html
76<perfect-scrollbar style="max-width: 600px; max-height: 400px;" [config]="config">
77 <div>Scrollable content</div>
78</perfect-scrollbar>
79```
80
81```javascript
82[config] // Custom config to override the global defaults.
83[disabled] // Disables the Perfect Scrollbar initialization.
84
85[usePSClass] // Use 'ps' class (needed by the ps theme styles).
86
87[autoPropagation] // Automatic swipe and wheel propagation control.
88[scrollIndicators] // Enable fading edges scroll indicators showing.
89
90(<psEventName>) // All Perfect Scrollbar events work as bindings.
91 // Event names are in camel case (not kebab case).
92 // Example: ps-y-reach-start -> psYReachStart
93```
94
95**DIRECTIVE USAGE**
96
97When using only the directive you need to provide your own theming or import the default theme:
98
99```css
100@import '~perfect-scrollbar/css/perfect-scrollbar.css';
101```
102
103Perfect Scrollbar directive should be used with div elements and can take optional custom configuration:
104
105```html
106<div class="ps" style="position: relative; max-width: 600px; max-height: 400px;" [perfectScrollbar]="config">
107 <div>Scrollable content</div>
108</div>
109```
110
111```javascript
112[perfectScrollbar] // Can be used to provide optional custom config.
113
114[disabled] // Disables the Perfect Scrollbar initialization.
115
116(<psEventName>) // All Perfect Scrollbar events work as bindings.
117 // Event namea are in camel case (not kebab case).
118 // Example: ps-y-reach-start -> psYReachStart
119```
120
121##### Available configuration options (custom / global configuration):
122
123```javascript
124handlers // List of event handlers to scroll the element.
125wheelSpeed // Scroll speed for the mousewheel event (Default: 1).
126swipeEasing // Use easing for the swipe scrolling (Default: true).
127suppressScrollX // Disable X axis in all situations (Default: false).
128suppressScrollY // Disable Y axis in all situations (Default: false).
129wheelPropagation // Propagate wheel events at the end (Default: false).
130useBothWheelAxes // Always use both of the wheel axes (Default: false).
131minScrollbarLength // Minimum size (px) for the scrollbar (Default: null).
132maxScrollbarLength // Maximum size (px) for the scrollbar (Default: null).
133scrollXMarginOffset // Offset before enabling the X scroller (Default: 0).
134scrollYMarginOffset // Offset before enabling the Y scroller (Default: 0).
135```
136
137For more detailed documentation with all the supported events / options see the the Perfect Scrollbar documentation.
138
139##### Available control / helper functions (provided by the directive):
140
141```javascript
142ps() // Returns reference to the PS instance.
143
144update() // Updates the scrollbar size and position.
145
146geometry(prefix) // Returns the geometry with specified prefix.
147position(absolute) // Returns the reach or absolute scroll position.
148
149scrollable(direction) // Checks if the given direction is scrollable.
150 // Direction can be: 'any', 'both', 'x', 'y'
151
152scrollTo(x, y, speed?) // Animate scroll to given x,y coordinates.
153scrollToY(position, speed?) // Animate scroll to given vertical position.
154scrollToX(position, speed?) // Animate scroll to given horizontal position.
155scrollToTop(offset?, speed?) // Animate scroll to given offset from the top.
156scrollToLeft(offset?, speed?) // Animate scroll to given offset from the left.
157scrollToRight(offset?, speed?) // Animate scroll to given offset from the right.
158scrollToBottom(offset?, speed?) // Animate scroll to given offset from the bottom.
159scrollToElement(element, offset?, speed?) // Animate scroll to given or matching HTML element.
160 // Input can be HTMLElement or a query selector string.
161```
162
163Above functions can be accessed through the directive reference (available as directiveRef in the component). Position and offset needs to be given in pixels and speed in milliseconds.