GithubHelp home page GithubHelp logo

hhy5277 / ngx-perfect-scrollbar Goto Github PK

View Code? Open in Web Editor NEW

This project forked from zefoy/ngx-perfect-scrollbar

0.0 1.0 0.0 4.29 MB

Angular wrapper library for the Perfect Scrollbar

License: MIT License

JavaScript 20.33% CSS 14.16% HTML 16.57% TypeScript 48.94%

ngx-perfect-scrollbar's Introduction

Angular Perfect Scrollbar

npm version

This 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.

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.

Quick links

Example application | StackBlitz example | Perfect Scrollbar documentation

Building the library

npm install
npm start

Running the example

cd example
npm install
npm start

Library development

npm link
cd example
npm link ngx-perfect-scrollbar

Installing and usage

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.

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]                // 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.

(<psEventName>)         // 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:

@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]      // Can be used to provide optional custom config.

[disabled]              // Disables the Perfect Scrollbar initialization.

(<psEventName>)         // 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):
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):
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(qs, offset?, speed?)   // Animate scroll to element matching query selectors.

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.

ngx-perfect-scrollbar's People

Contributors

antti-pyykkonen avatar argannor avatar brunonocetti avatar criticalbh avatar j2l4e avatar mtraynham avatar rdkmaster avatar reyiyo avatar sconix avatar sibiraj-s avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.