Skip to content
Calm motion: animations on this site only fade, with no movement

Affix ​

Sticky wrapper with an offset

A wrapper that sticks to the top edge of the window when the page scrolls past it. Use it for a table header, a toolbar, or a section nav. It is plain CSS position: sticky, with one observer that reports when it is stuck.

Basic
Scroll down

Line 1 of the scrolling area.

Line 2 of the scrolling area.

Line 3 of the scrolling area.

Line 4 of the scrolling area.

Line 5 of the scrolling area.

Line 6 of the scrolling area.

Line 7 of the scrolling area.

Line 8 of the scrolling area.

Line 9 of the scrolling area.

Line 10 of the scrolling area.

Line 11 of the scrolling area.

Line 12 of the scrolling area.

Line 13 of the scrolling area.

Line 14 of the scrolling area.

  • offset is the gap in px from the top edge, for example below a fixed header. It sets top and the observer margin.
  • The default slot gets stuck. Use it to add a plate when the box leaves its resting place. v-model:stuck reads the same state.
  • Attributes go to the sticky box, not to the probe that the component renders before it.
  • Sticky positioning works only inside a parent that is taller than the box. A parent with overflow: hidden breaks it.
  • stuck follows the window scroll. Inside a scroll container, sticky still works but stuck can be wrong.

Usage ​

ts
import { BlessAffix } from "blessing-ui";

API ​

Props

NameTypeDefaultDescription
offsetnumber0distance in px from the top edge where it sticks. The window scroll sets `stuck`.
stuckbooleanfalse

Events

NamePayloadDescription
update:stuck[value: boolean]

Slots

NameScopeDescription
default{ stuck: boolean; }

Released under the MIT License. Character names and artwork belong to their owners.