mirror of
https://github.com/akveo/ngx-admin.git
synced 2025-12-22 18:30:14 +01:00
scrollPosition - baScrollPosition
This commit is contained in:
parent
8b673b1f48
commit
5f360a73a8
6 changed files with 12 additions and 11 deletions
|
|
@ -0,0 +1,25 @@
|
|||
import {Directive, Input, Output, EventEmitter, HostListener} from '@angular/core';
|
||||
|
||||
@Directive({
|
||||
selector: '[baScrollPosition]'
|
||||
})
|
||||
export class BaScrollPosition {
|
||||
|
||||
@Input() public maxHeight:number;
|
||||
@Output() public scrollChange:EventEmitter<boolean> = new EventEmitter<boolean>();
|
||||
|
||||
private _isScrolled:boolean;
|
||||
|
||||
public ngOnInit():void {
|
||||
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