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
}
    

静态属性

属性说明
static ngInjectableDef: defineInjectable({ providedIn: 'root', factory: () => new BrowserViewportScroller(inject(DOCUMENT), window) })

方法

Configures the top offset used when scrolling to an anchor.

abstract setOffset(offset: [number, number] | (() => [number, number])): void
      
      abstract setOffset(offset: [number, number] | (() => [number, number])): void
    
参数
offset [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]
      
      abstract getScrollPosition(): [number, number]
    
参数

没有参数。

返回值

[number, number]

Sets the scroll position.

abstract scrollToPosition(position: [number, number]): void
      
      abstract scrollToPosition(position: [number, number]): void
    
参数
position [number, number]
返回值

void

Scrolls to the provided anchor.

abstract scrollToAnchor(anchor: string): void
      
      abstract scrollToAnchor(anchor: string): void
    
参数
anchor string
返回值

void

Disables automatic scroll restoration provided by the browser.

abstract setHistoryScrollRestoration(scrollRestoration: "auto" | "manual"): void
      
      abstract setHistoryScrollRestoration(scrollRestoration: "auto" | "manual"): void
    
参数
scrollRestoration "auto" | "manual"
返回值

void

See also window.history.scrollRestoration info