Skip to main content
VelinStyle v0.9.0
⌂ Home
  1. Docs
  2. Components
  3. Scroll to top

Scroll to top

Add <velin-scroll-top> once per page. It appears after scrolling past a threshold and scrolls smoothly to the top (respects prefers-reduced-motion).

Declarative attribute

Without a custom element in markup, set velin-scroll-top on <body> (or any element). Requires bootFromDOM(document, { attributes: true }) or bootAttributes():

<body velin-scroll-top="400">
  ...
</body>

See HTML attributes guide.

Basic

Scroll this page to see the button in the lower corner.

<velin-scroll-top threshold="300"></velin-scroll-top>

Attributes

AttributeDefaultNotes
threshold300Scroll offset (px) before the button is shown

Styling

Position via CSS variables on :host:

velin-scroll-top {
  --velin-scroll-top-bottom: 1.5rem;
  --velin-scroll-top-end: 1.5rem;
}

Accessibility