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

Configures the top offset used when scrolling to an anchor.

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

Parameters

offset

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

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.

Returns the current scroll position.

abstract getScrollPosition(): [number, number]

Parameters

There are no parameters.

Returns

[number, number]

Sets the scroll position.

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

Parameters

position

Type: [number, number].

Returns

void

Scrolls to the provided anchor.

abstract scrollToAnchor(anchor: string): void

Parameters

anchor

Type: string.

Returns

void

Disables automatic scroll restoration provided by the browser.

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

Parameters

scrollRestoration

Type: 'auto' | 'manual'.

Returns

void

See also window.history.scrollRestoration info

© 2010–2019 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://v6.angular.io/api/common/ViewportScroller