|
| 1 | +<p align="center"> |
| 2 | + <img height="256px" width="256px" style="text-align: center;" src="https://cdn.rawgit.com/tinesoft/ngx-wow/master/demo/src/assets/logo.svg"> |
| 3 | +</p> |
| 4 | + |
| 5 | +# ngx-wow - Angular module for WOW.js. |
| 6 | + |
| 7 | +[](https://badge.fury.io/js/ngx-wow) |
| 8 | +[](https://travis-ci.org/tinesoft/ngx-wow) |
| 9 | +[](https://coveralls.io/github/tinesoft/ngx-wow?branch=master) |
| 10 | +[](https://david-dm.org/tinesoft/ngx-wow) |
| 11 | +[](https://david-dm.org/tinesoft/ngx-wow#info=devDependencies) |
| 12 | +[](https://greenkeeper.io/) |
| 13 | + |
| 14 | +## Demo |
| 15 | + |
| 16 | +View all the directives in action at https://tinesoft.github.io/ngx-wow |
| 17 | + |
| 18 | +## Dependencies |
| 19 | +* [Angular](https://angular.io) (*requires* Angular 2 or higher, tested with 2.0.0) |
| 20 | + |
| 21 | +## Installation |
| 22 | +Install above dependencies via *npm*. |
| 23 | + |
| 24 | +Now install `ngx-wow` via: |
| 25 | +```shell |
| 26 | +npm install --save ngx-wow |
| 27 | +``` |
| 28 | + |
| 29 | +--- |
| 30 | +##### SystemJS |
| 31 | +>**Note**:If you are using `SystemJS`, you should adjust your configuration to point to the UMD bundle. |
| 32 | +In your systemjs config file, `map` needs to tell the System loader where to look for `ngx-wow`: |
| 33 | +```js |
| 34 | +map: { |
| 35 | + 'ngx-wow': 'node_modules/ngx-wow/bundles/ngx-wow.umd.js', |
| 36 | +} |
| 37 | +``` |
| 38 | +--- |
| 39 | + |
| 40 | +Once installed you need to import the main module: |
| 41 | +```js |
| 42 | +import { NgwWowModule } from 'ngx-wow'; |
| 43 | +``` |
| 44 | +The only remaining part is to list the imported module in your application module. The exact method will be slightly |
| 45 | +different for the root (top-level) module for which you should end up with the code similar to (notice ` NgwWowModule.forRoot()`): |
| 46 | +```js |
| 47 | +import { NgwWowModule } from 'ngx-wow'; |
| 48 | + |
| 49 | +@NgModule({ |
| 50 | + declarations: [AppComponent, ...], |
| 51 | + imports: [NgwWowModule.forRoot(), ...], |
| 52 | + bootstrap: [AppComponent] |
| 53 | +}) |
| 54 | +export class AppModule { |
| 55 | +} |
| 56 | +``` |
| 57 | + |
| 58 | +Other modules in your application can simply import ` NgwWowModule `: |
| 59 | + |
| 60 | +```js |
| 61 | +import { NgwWowModule } from 'ngx-wow'; |
| 62 | + |
| 63 | +@NgModule({ |
| 64 | + declarations: [OtherComponent, ...], |
| 65 | + imports: [NgwWowModule, ...], |
| 66 | +}) |
| 67 | +export class OtherModule { |
| 68 | +} |
| 69 | +``` |
| 70 | + |
| 71 | +## Usage |
| 72 | +Once the module is imported, you can use the `NgwWowService` in your component (i.e. `AppComponent`) to trigger reveal animation by calling `init()` or to be notified by WOW when an element is revealed. |
| 73 | + |
| 74 | +Here is how it works: |
| 75 | + |
| 76 | +```ts |
| 77 | +import { Component, OnInit, OnDestroy } from '@angular/core'; |
| 78 | +import { Router, NavigationEnd } from '@angular/router'; |
| 79 | +import { NgwWowService } from 'ngx-wow'; |
| 80 | +import { Subscription } from 'rxjs/Subscription'; |
| 81 | + |
| 82 | +@Component({ |
| 83 | + selector: 'app-root', |
| 84 | + templateUrl: './app.component.html', |
| 85 | + styleUrls: ['./app.component.scss'] |
| 86 | +}) |
| 87 | +export class AppComponent implements OnInit, OnDestroy { |
| 88 | + |
| 89 | + //keep refs to subscription to be abble to unsubscribe later |
| 90 | + private wowSubscription: Subscription; |
| 91 | + |
| 92 | + constructor(private router: Router, private wowService: NgwWowService){ |
| 93 | + this.router.events.filter(event => event instanceof NavigationEnd).subscribe(event => { |
| 94 | + // Reload WoW animations when done navigating to page, |
| 95 | + // but you are free to call it whenever/wherever you like |
| 96 | + this.wowService.init(); |
| 97 | + }); |
| 98 | + |
| 99 | + } |
| 100 | + |
| 101 | + ngOnInit() { |
| 102 | + // subscribe to WOW observable to react when an element is revealed |
| 103 | + this.wowSubscription = this.wowService.itemRevealed$.subscribe( |
| 104 | + (item:HTMLElement) => { |
| 105 | + // do whatever you want with revealed element |
| 106 | + }); |
| 107 | + } |
| 108 | + |
| 109 | + ngOnDestroy() { |
| 110 | + // unsubscribe to cookieconsent observables to prevent memory leaks |
| 111 | + this.wowSubscription.unsubscribe(); |
| 112 | + } |
| 113 | +} |
| 114 | + |
| 115 | +``` |
| 116 | + |
| 117 | +See [WOW.js Documentation](https://github.com/matthieua/WOW#advanced-usage) to see more about how to customize animation settings. |
| 118 | + |
| 119 | +## Credits |
| 120 | + |
| 121 | +`ngx-wow` is built upon [WOW.js](http://mynameismatthieu.com/WOW/), created by [Matthieu Aussaguel](http://mynameismatthieu.com/) |
| 122 | + |
| 123 | +## License |
| 124 | + |
| 125 | +Copyright (c) 2017 Tine Kondo. Licensed under the MIT License (MIT) |
| 126 | + |
0 commit comments