File

src/services/scroll-to.service.ts

Index

Methods

Constructor

constructor()

Methods

scrollTo
scrollTo(elementId: string, options?: boolean | ScrollIntoViewOptions)
Parameters :
Name Type Optional
elementId string No
options boolean | ScrollIntoViewOptions Yes
Returns : void
scrollToWithinContent
scrollToWithinContent(content: IonContent, elementId: string)
Parameters :
Name Type Optional
content IonContent No
elementId string No
Returns : void
import {Injectable} from '@angular/core';
import {IonContent} from '@ionic/angular';

@Injectable({
    providedIn: 'root'
})
export class ScrollToService {

    constructor() {
    }

    scrollTo(elementId: string, options?: boolean | ScrollIntoViewOptions): void {
        const element = document.getElementById(elementId);
        if (!element) {
            return;
        }
        element.scrollIntoView(options || {
            behavior: 'smooth'
        });
    }

    scrollToWithinContent(content: IonContent, elementId: string): void {
        const y = document.getElementById(elementId).offsetTop;
        content.scrollToPoint(0, y, 500).then();
    }
}

results matching ""

    No results matching ""