ViewportScroller

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 }

静态属性

属性名类型说明
ngInjectableDef

方法

Configures the top offset used when scrolling to an anchor.

abstract setOffset(offset: [number, number] | (() => [number, number])): void

参数

offset

Type: [number, number] | (() => [number, number]).

返回值

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.

Returns the current scroll position.

abstract getScrollPosition(): [number, number]

参数

没有参数。

返回值

[number, number]

Sets the scroll position.

abstract scrollToPosition(position: [number, number]): void

参数

position

Type: [number, number].

返回值

void

Scrolls to the provided anchor.

abstract scrollToAnchor(anchor: string): void

参数

anchor

Type: string.

返回值

void

Disables automatic scroll restoration provided by the browser. See also window.history.scrollRestoration info

abstract setHistoryScrollRestoration(scrollRestoration: 'auto' | 'manual'): void

参数

scrollRestoration

Type: 'auto' | 'manual'.

返回值

void