ViewportScroller
class
Manages the scroll position.
abstract class ViewportScroller {
static ngInjectableDef: defineInjectable({ providedIn: 'root', factory: () => new BrowserViewportScroller(inject(DOCUMENT), window) })
abstract setOffset(offset: [number, number] | (() => [number, number])): void
abstract getScrollPosition(): [number, number]
abstract scrollToPosition(position: [number, number]): void
abstract scrollToAnchor(anchor: string): void
abstract setHistoryScrollRestoration(scrollRestoration: 'auto' | 'manual'): void
} Static properties
| Property | Description |
|---|---|
static ngInjectableDef: defineInjectable({ providedIn: 'root', factory: () => new BrowserViewportScroller(inject(DOCUMENT), window) }) |
Methods
| setOffset() | ||
|---|---|---|
| Configures the top offset used when scrolling to an anchor. | ||
|
| offset | Type: |
Returns
void
When given a tuple with two number, the service will always use the numbers. When given a function, the service will invoke the function every time it restores scroll position.
| getScrollPosition() |
|---|
| Returns the current scroll position. |
|
| scrollToPosition() | ||
|---|---|---|
| Sets the scroll position. | ||
|
| position | Type: |
Returns
void
| scrollToAnchor() | ||
|---|---|---|
| Scrolls to the provided anchor. | ||
|
| anchor | Type: |
Returns
void
| setHistoryScrollRestoration() | ||
|---|---|---|
| Disables automatic scroll restoration provided by the browser. | ||
|
| scrollRestoration | Type: |
Returns
void
© 2010–2019 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://v6.angular.io/api/common/ViewportScroller