Angular 2+ wrapper for in-view.js
https://ihym.github.io/ngx-in-view/
Install through npm:
npm install --save ngx-in-view- enter: EventEmitter
<any>: Emits whenever the element enters the viewport. - exit: EventEmitter
<any>: Emits whenever the element exits the viewport. - enterOnce: EventEmitter
<any>: Emits when the element enters the viewport for the first time. - exitOnce: EventEmitter
<any>: Emits when the element exits the viewport for the first time.
Note: For every output, if not bound, no handler will be registered for the respective events.
- is(): Check if element is in the viewport.
Once installed you need to import our main module into your application module by calling InViewModule.forRoot(). You should end up with code similar to this:
import {AppComponent} from '...';
import {InViewModule} from 'ngx-in-view/ngx-in-view';
@NgModule({
imports: [..., InViewModule.forRoot()],
declarations: [AppComponent, ...],
bootstrap: [AppComponent],
})
export class AppModule {}Optionally, you can pass an object to the forRoot method, to configure ngx-in-view during the initialization of the application, in order to provide your own default values. For example:
@NgModule({
imports: [
...,
InViewModule.forRoot({
threshold: 1, // Override this specific property
...
})
],
})
export class AppModule {}Currently available options can be found here.
If you want to change some config properties during runtime, you can easily achieve it by utilizing the update method like this:
import {InViewConfig} from 'ngx-in-view/ngx-in-view';
export class AppComponent {
constructor(private config: InViewConfig) {}
changeConfig() {
this.config.update({
threshold: 0.5,
...,
});
}
}npm run buildIf you want to watch your source files for changes and build every time use:
npm startNote: Generated output is placed into the node_modules/ngx-card folder.
The best way to see your changes in action, is to use our demo page locally. Run:
npm run demowhich will create a development server accessible through http:localhost:1111.
In conjunction with npm start in another command tab you have a fully working environment!
All demo resources can be found in the /demo folder.
MIT @ Vasilis Diakomanolis