Change pageTop bg onScroll.

This commit is contained in:
smartapant 2016-04-27 18:21:52 +03:00
parent 0b399a4a1b
commit d5dab605a9
4 changed files with 34 additions and 3 deletions

View file

@ -0,0 +1,23 @@
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);
}
}
}