Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zefoy/angular2-perfect-scrollbar
Angular wrapper library for the Perfect Scrollbar
https://github.com/zefoy/angular2-perfect-scrollbar
Last synced: 3 months ago
JSON representation
Angular wrapper library for the Perfect Scrollbar
- Host: GitHub
- URL: https://github.com/zefoy/angular2-perfect-scrollbar
- Owner: zefoy
- License: mit
- Created: 2016-08-27T19:32:32.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2023-07-07T07:11:30.000Z (over 1 year ago)
- Last Synced: 2024-05-20T20:20:14.190Z (6 months ago)
- Language: TypeScript
- Homepage:
- Size: 7.08 MB
- Stars: 519
- Watchers: 23
- Forks: 117
- Open Issues: 86
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-angular-components - angular2-perfect-scrollbar - Angular 2 wrapper library for perfect scrollbar (Uncategorized / Uncategorized)
README
# Angular Perfect Scrollbar
This 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.
This 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 here.
### EOL notice
Version 10.0.0 will be the last release of this library. I recommend you to switch to using native Angular scrollbar libraries such as ngx-scrollbar. There are also forks available (just search with perfect-scrollbar from npm registry) if you really want to use a wrapper library for perfect scrollbar. For the sake of good code and practices I would personally use a native Angular libraries since using Angular wrappers for DOM libraries will always have limitations and performance issues.
Even though I should not need to tell about the motivation for EOL, but since some seem to think its required the main reason for EOL this library was that at the time perfect-scrollbar library itself was not maintained (do not know the current situation though) and none of the bugs it had were being addressed. That and the native Angular libraries coming to existence that do this better sealed the decision to end this library.
### Quick links
[Example application](https://zefoy.github.io/ngx-perfect-scrollbar/)
|
[StackBlitz example](https://stackblitz.com/github/zefoy/ngx-perfect-scrollbar/tree/master)
|
[Perfect Scrollbar documentation](https://github.com/utatti/perfect-scrollbar/)### Building the library
```bash
npm install
npm run build
```### Running the example
```bash
npm install
npm run start
```### Installing and usage
```bash
npm install ngx-perfect-scrollbar --save
```##### Load the module for your app (with global configuration):
Providing the global configuration is optional and when used you should only provide the configuration in your root module.
```javascript
import { PerfectScrollbarModule } from 'ngx-perfect-scrollbar';
import { PERFECT_SCROLLBAR_CONFIG } from 'ngx-perfect-scrollbar';
import { PerfectScrollbarConfigInterface } from 'ngx-perfect-scrollbar';const DEFAULT_PERFECT_SCROLLBAR_CONFIG: PerfectScrollbarConfigInterface = {
suppressScrollX: true
};@NgModule({
...
imports: [
...
PerfectScrollbarModule
],
providers: [
{
provide: PERFECT_SCROLLBAR_CONFIG,
useValue: DEFAULT_PERFECT_SCROLLBAR_CONFIG
}
]
})
```##### Use it in your HTML template (with custom configuration):
This 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.
The 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.
**COMPONENT USAGE**
Simply replace the element that would ordinarily be passed to `PerfectScrollbar` with the perfect-scollbar component.
```html
Scrollable content```
```javascript
[config] // Custom config to override the global defaults.
[disabled] // Disables the Perfect Scrollbar initialization.[usePSClass] // Use 'ps' class (needed by the ps theme styles).
[autoPropagation] // Automatic swipe and wheel propagation control.
[scrollIndicators] // Enable fading edges scroll indicators showing.() // All Perfect Scrollbar events work as bindings.
// Event names are in camel case (not kebab case).
// Example: ps-y-reach-start -> psYReachStart
```**DIRECTIVE USAGE**
When using only the directive you need to provide your own theming or import the default theme:
```css
@import '~perfect-scrollbar/css/perfect-scrollbar.css';
```Perfect Scrollbar directive should be used with div elements and can take optional custom configuration:
```html
Scrollable content
``````javascript
[perfectScrollbar] // Can be used to provide optional custom config.[disabled] // Disables the Perfect Scrollbar initialization.
() // All Perfect Scrollbar events work as bindings.
// Event namea are in camel case (not kebab case).
// Example: ps-y-reach-start -> psYReachStart
```##### Available configuration options (custom / global configuration):
```javascript
handlers // List of event handlers to scroll the element.
wheelSpeed // Scroll speed for the mousewheel event (Default: 1).
swipeEasing // Use easing for the swipe scrolling (Default: true).
suppressScrollX // Disable X axis in all situations (Default: false).
suppressScrollY // Disable Y axis in all situations (Default: false).
wheelPropagation // Propagate wheel events at the end (Default: false).
useBothWheelAxes // Always use both of the wheel axes (Default: false).
minScrollbarLength // Minimum size (px) for the scrollbar (Default: null).
maxScrollbarLength // Maximum size (px) for the scrollbar (Default: null).
scrollXMarginOffset // Offset before enabling the X scroller (Default: 0).
scrollYMarginOffset // Offset before enabling the Y scroller (Default: 0).
```For more detailed documentation with all the supported events / options see the the Perfect Scrollbar documentation.
##### Available control / helper functions (provided by the directive):
```javascript
ps() // Returns reference to the PS instance.update() // Updates the scrollbar size and position.
geometry(prefix) // Returns the geometry with specified prefix.
position(absolute) // Returns the reach or absolute scroll position.scrollable(direction) // Checks if the given direction is scrollable.
// Direction can be: 'any', 'both', 'x', 'y'scrollTo(x, y, speed?) // Animate scroll to given x,y coordinates.
scrollToY(position, speed?) // Animate scroll to given vertical position.
scrollToX(position, speed?) // Animate scroll to given horizontal position.
scrollToTop(offset?, speed?) // Animate scroll to given offset from the top.
scrollToLeft(offset?, speed?) // Animate scroll to given offset from the left.
scrollToRight(offset?, speed?) // Animate scroll to given offset from the right.
scrollToBottom(offset?, speed?) // Animate scroll to given offset from the bottom.
scrollToElement(element, offset?, speed?) // Animate scroll to given or matching HTML element.
// Input can be HTMLElement or a query selector string.
```Above 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.