I am creating a page in which animation will occur on scrolling down the page, when the element is visible on the viewport its corresponding animation will occur. As I'm using Angular2, thought of writing scroll function using it. I searched the whole day and found that HostListener will satisfy what I looked for. But, my problem is "Multiple pages have been used". Hence I need the scroll function to occur only one the required page. Is there any solution for this.
I also think of some possible solution as listed:
- We can destroy the Listener
- Adding a Listener for a particular page
If the above mentioned are possible then how could we do that.
My Code:
import {Component,HostListener} from '@angular/core';
@Component({
selector: 'my-app',
templateUrl:'src/html/home.html',
})
export class Home {
@HostListener('window:scroll', ['$event'])
onScroll(e){
// My animation code
}
}
HTML Code:
<div (window:resize)="onResize($event)">
//some code
</div>