src/services/scroll-to.service.ts
Methods |
constructor()
|
Defined in src/services/scroll-to.service.ts:7
|
scrollTo | |||||||||
scrollTo(elementId: string, options?: boolean | ScrollIntoViewOptions)
|
|||||||||
Defined in src/services/scroll-to.service.ts:12
|
|||||||||
Parameters :
Returns :
void
|
scrollToWithinContent | |||||||||
scrollToWithinContent(content: IonContent, elementId: string)
|
|||||||||
Defined in src/services/scroll-to.service.ts:22
|
|||||||||
Parameters :
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();
}
}