File

my-lib/classes/scroller.ts

Index

Properties
Methods

Constructor

constructor(ele: ElementRef)
Parameters :
Name Type Optional Description
ele ElementRef

Methods

Private _updateViewportSize
_updateViewportSize()
Returns : void
getViewportRect
getViewportRect()
Returns : ClientRect
getViewportScrollPosition
getViewportScrollPosition()
Returns : { top: any; left: any; }
getViewportSize
getViewportSize()

Properties

_viewportSize
_viewportSize: any
Type : any
Public ele
ele: ElementRef
Type : ElementRef
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,
        };
    }
}

results matching ""

    No results matching ""