Angular Perfect Scrollbar
This fork of ngx-perfect-scrollbar is an Angular wrapper library for the 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.
Quick links
Example application
|
Perfect Scrollbar documentation
Installing and usage
npm install @harvest-dev/ngx-perfect-scrollbar --save
Requirements
-
peerDependencies:
angular
16.1.0 and moreangular/cdk
16.1.0 and more
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.
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.
<perfect-scrollbar style="max-width: 600px; max-height: 400px;" [config]="config">
<div>Scrollable content</div>
</perfect-scrollbar>
[config]
[disabled]
[usePSClass]
[autoPropagation]
[scrollIndicators]
(<psEventName>)
DIRECTIVE USAGE
When using only the directive you need to provide your own theming or import the default theme:
@import '~perfect-scrollbar/css/perfect-scrollbar.css';
Perfect Scrollbar directive should be used with div elements and can take optional custom configuration:
<div class="ps" style="position: relative; max-width: 600px; max-height: 400px;" [perfectScrollbar]="config">
<div>Scrollable content</div>
</div>
[perfectScrollbar]
[disabled]
(<psEventName>)
Available configuration options (custom / global configuration):
handlers;
wheelSpeed;
swipeEasing;
suppressScrollX;
suppressScrollY;
wheelPropagation;
useBothWheelAxes;
minScrollbarLength;
maxScrollbarLength;
scrollXMarginOffset;
scrollYMarginOffset;
For more detailed documentation with all the supported events / options see the the Perfect Scrollbar documentation.
Available control / helper functions (provided by the directive):
ps()
update()
geometry(prefix)
position(absolute)
scrollable(direction)
scrollTo(x, y, speed?)
scrollToY(position, speed?)
scrollToX(position, speed?)
scrollToTop(offset?, speed?)
scrollToLeft(offset?, speed?)
scrollToRight(offset?, speed?)
scrollToBottom(offset?, speed?)
scrollToElement(element, offset?, speed?)
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.
Publishing the library
npm run build:lib
npm run publish:lib
Update Demo
npm run build:demo
Running the example
npm install
npm run start