import { WrScroll } from 'ngwr/scroll';WrScroll
Scroll to an element, id, selector or position, with an offset for sticky headers.
Installation
Import the class. This entry point has no stylesheet.
Usage
Pass container to scroll an element instead of the window.
private readonly scroll = inject(WrScroll);
this.scroll.to('#section-three', { offset: 80 });
this.scroll.toTop({ smooth: false });
this.scroll.intoView(myEl, { offset: 64 });API
| Name | Description | Type | Default |
|---|---|---|---|
to(target, options?) | Scroll to an element, id (#foo), selector, or { top, left } coords. | (t, opts?) => void | — |
intoView(el, options?) | Scroll to an element. Same options as to(). | (el, opts?) => void | — |
toTop(options?) | Scroll the page (or container) to the top. | (opts?) => void | — |
options.offset | Pixels subtracted from the target, for a sticky header. No effect on toTop(). | number | 0 |
options.smooth | Smooth or instant. Always instant under prefers-reduced-motion: reduce. | boolean | true |
options.container | The element to scroll instead of the window. | Window | Element | window |
Dependencies
| Used by | Anchor, Back to Top |
|---|