ngx-admin/src/app/theme/directives/scrollPosition.directive.ts

23 lines
656 B
TypeScript
Raw Normal View History

2016-04-27 18:21:52 +03:00
import {Directive, Input, Output, EventEmitter, HostListener, ElementRef} from 'angular2/core';
@Directive({
selector: '[scrollPosition]'
})
export class ScrollPosition {
@Input() maxHeight: Number;
@Output() scrollChange:EventEmitter<Boolean> = new EventEmitter<Boolean>();
private _isScrolled: Boolean;
ngOnInit() {
this.onWindowScroll();
}
@HostListener('window:scroll')
onWindowScroll() : void {
let isScrolled = window.scrollY > this.maxHeight;
if (isScrolled !== this._isScrolled) {
this._isScrolled = isScrolled;
this.scrollChange.emit(isScrolled);
}
}
}