Angular 2 directives for ScrollReveal JS
ng2-scrollreveal -ScrollReveal JS is a great library that allows easy scroll animations for web and mobile browsers.
Demo
View all the directives in action at https://tinesoft.github.io/ng2-scrollreveal
Dependencies
- Angular 2 (requires Angular 2 or higher, tested with 2.0.0)
- ScrollReveal (requires ScrollReveal 3.2 or higher, tested with 3.2.0)
Installation
Install above dependencies via npm. In particular for ScrollReveal JS
, run:
npm install --save scrollreveal
Angular-CLI
Note: If you are using
angular-cli
to build your app, make sure thatscrollreveal
is properly listed as a global library, by editing yourangular-cli.json
as such:
"scripts": [
"../node_modules/scrollreveal/dist/scrollreveal.js"
],
SystemJS
Note:If you are using
SystemJS
, you should adjust your configuration to point to the UMD bundle. In your systemjs config file,map
needs to tell the System loader where to look forng2-scrollreveal
:
map: 'ng2-scrollreveal': 'node_modules/ng2-scrollreveal/bundles/ng2-scrollreveal.min.js'
In your systemjs config file, meta
needs to tell the System loader how to load scrollreveal
:
meta: './node_modules/scrollreveal/dist/scrollreveal.min.js': format: 'amd'
In your index.html file, add script tag to load scrollreveal
globally:
<!-- 1. Configure SystemJS --> <!-- 2. Add scrollreveal dependency-->
Now install ng2-scrollreveal
via:
npm install --save ng2-scrollreveal
Once installed you need to import the main module:
;
The only remaining part is to list the imported module in your application module. The exact method will be slightly
different for the root (top-level) module for which you should end up with the code similar to (notice NgsRevealModule.forRoot()
):
; @
Other modules in your application can simply import NgsRevealModule
:
; @
Usage
The library is composed of two main directives: ngsReveal
and ngsRevealSet
.
ngsReveal Directive
Use this directive to reveal/hide a single DOM element upon scroll.
Basic Usage:
..
With Custom Options:
You can also pass in a custom configuration object to the directive.
..
This will override the default configuration used when revealing this particular element. When no configuration is passed in, the directive uses the default configuration defined at component or at application level.
Configuration options are the same as ScrollReveal JS configuration object.
ngsRevealSet Directive
Use this directive to reveal/hide a set of DOM elements upon scroll.
[ngsSelector]
attribute is required, and defines which child items must be revealed/hidden on scroll.
Note: The value is a list of CSS selectors (comma-separated).
Basic Usage:
Item 1 Item 2 Item 3 Item 4 Item 5 (will not be animated)
With Custom Options:
Item 1 Item 2 Item 3 Item 4 Item 5 (will not be animated)
Configuration options are the same as ScrollReveal JS configuration object.
Sequentially animated items:
Child items inside the parent set can be sequentially animated, by adding the [ngsRevealInterval]
attribute.
Note: The interval is the time until the next element in the sequence begins its reveal, which is separate from the time until the element’s animation completes. In this example, the sequence interval is 50 milliseconds.
Item 1 Item 2 Item 3 Item 4 Item 5 (will not be animated)
Credits
ng2-scrollreveal
is built upon ScrollReveal JS by Julian Lloyd. Thanks to him for the great work!