mirror of
https://github.com/akveo/ngx-admin.git
synced 2026-03-05 13:20:16 +01:00
Change pageTop bg onScroll.
This commit is contained in:
parent
0b399a4a1b
commit
d5dab605a9
4 changed files with 34 additions and 3 deletions
23
src/app/theme/directives/scrollPosition.directive.ts
Normal file
23
src/app/theme/directives/scrollPosition.directive.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue