my-lib/classes/scroller.ts
Properties |
|
Methods |
constructor(ele: ElementRef)
|
||||||||
Defined in my-lib/classes/scroller.ts:4
|
||||||||
Parameters :
|
Private _updateViewportSize |
_updateViewportSize()
|
Defined in my-lib/classes/scroller.ts:17
|
Returns :
void
|
getViewportRect |
getViewportRect()
|
Defined in my-lib/classes/scroller.ts:34
|
Returns :
ClientRect
|
getViewportScrollPosition |
getViewportScrollPosition()
|
Defined in my-lib/classes/scroller.ts:9
|
Returns :
{ top: any; left: any; }
|
getViewportSize |
getViewportSize()
|
Defined in my-lib/classes/scroller.ts:24
|
Returns :
Readonly<literal type>
|
_viewportSize |
_viewportSize:
|
Type : any
|
Defined in my-lib/classes/scroller.ts:4
|
Public ele |
ele:
|
Type : ElementRef
|
Defined in my-lib/classes/scroller.ts:6
|
import { ElementRef } from '@angular/core';
export class Scroller {
_viewportSize: any;
constructor(
public ele: ElementRef
) { }
getViewportScrollPosition() {
const ele = this.ele.nativeElement;
const documentRect = ele.getBoundingClientRect();
const top = -documentRect.top || ele.scrollTop || 0;
const left = -documentRect.left || ele.scrollLeft || 0;
return { top, left };
}
private _updateViewportSize() {
this._viewportSize = {
width: this.ele.nativeElement.offsetWidth,
height: this.ele.nativeElement.offsetHeight
};
}
getViewportSize(): Readonly<{ width: number, height: number }> {
if (!this._viewportSize || !this._viewportSize.height || !this._viewportSize.width ) {
this._updateViewportSize();
}
return {
width: this._viewportSize.width,
height: this._viewportSize.height
};
}
getViewportRect(): ClientRect {
const scrollPosition = this.getViewportScrollPosition();
const { width, height } = this.getViewportSize();
return {
top: scrollPosition.top,
left: scrollPosition.left,
bottom: scrollPosition.top + height,
right: scrollPosition.left + width,
height,
width,
};
}
}