layoutcontrollerz-sticky

Sticky

Sticks an element to the viewport edge on scroll, with start/end boundaries, show-on-up reveal, overflow handling, and native-sticky fallback.

Attributes

AttributeTypeDefaultDescription
position'top' | 'bottom''top'Edge the element sticks to: top once scrolled past its natural position, or bottom of the viewport.
offsetstring'0'Distance from the sticking edge. Accepts a length (px, rem, em, viewport units, or % of the viewport height), a CSS selector whose visible height is used, selector + length / selector - length, or !selector for the nearest matching ancestor.
offset-endstring'0'Distance from the opposite edge, used when computing overflow and the bottom sticking position; accepts the same syntax as offset.
startstring''Scroll boundary where sticking begins: a length past the natural position (% of the element height), true/parent for the parent's inner bottom edge, or a selector for an element's edge.
endstring''Scroll boundary where sticking stops: empty/true/parent for the parent's inner bottom, false/none for the document end, a length past the element, or a selector for an element's bottom edge.
show-on-upbooleanfalseOnly sticks while scrolling up; scrolling down hides the fixed element, playing the leave animation when animation is set.
overflow-flipbooleanfalseWhen the element is taller than the viewport, flips it to stick from the opposite edge so its far end stays reachable instead of scrolling the overflow.
animationstring''Animation preset played when the fixed element enters or leaves (with show-on-up, or when scrolling below its natural position).
durationnumber150Animation duration in milliseconds; non-finite or negative values fall back to 150.
mediastring''Media query that enables sticking; accepts a full query, a breakpoint shorthand (sm, md, lg, xl, 2xl), or a bare pixel number. When it stops matching, the element returns to its natural position and is marked inactive.
target-offsetstring''Enables hash-navigation compensation: after jumping to an anchor, scrolls back so the sticky element does not cover the target. true adds no extra gap, a length adds clearance, and false disables it.
sel-targetstring''CSS selector for a descendant that receives the active/inactive classes instead of the host.
Inherited from Base
AttributeTypeDefaultDescription
clsstring''Adds classes to named parts as key: classes pairs; a plain string targets the default part.
stlstring''Adds inline styles to named parts as key: styles pairs; a plain string targets the default part.

Custom Styling (cls / stl)

Default cls target:active · defaultstl target:host-inner

KeyDefault classclsstlDescription
activez-activeyesnoClass applied while the element is sticking (or to sel-target); the default cls target for this component.
belowz-sticky-belowyesnoClass applied once the page has scrolled past the element's natural position.
fixedz-sticky-fixedyesnoClass applied while the element is position: fixed rather than native sticky.
inactive—yesnoClass applied while the element is not sticking; empty by default.

Events

EventDetailFlagsDescription
z-sticky:active{ fixed: boolean; below: boolean; scroll: number; target: HTMLElement }bubblesFires when the element starts sticking. Detail carries fixed, below, scroll, and target.
z-sticky:change{ active: boolean; fixed: boolean; below: boolean; scroll: number; target: HTMLElement }bubblesFires on any active-state change; detail adds an active boolean to the fixed, below, scroll, and target fields.
z-sticky:inactive{ fixed: boolean; below: boolean; scroll: number; target: HTMLElement }bubblesFires when the element stops sticking, with the same detail shape as active.
z-sticky:mount · from ControllerRecord<string, unknown>bubblesFires when deferred template content is mounted into the container.

Methods

SignatureDescription
isActive(): booleanReturns whether the element is currently sticking.
isBelow(): booleanReturns whether the page has scrolled past the element's natural position.
isFixed(): booleanReturns whether the element is currently position: fixed (as opposed to native sticky or static).
refresh(): voidRe-measures the element and viewport and re-syncs the sticky state.

Data Hooks

AttributeValuesApplies toRoleDescription
data-fn · from ControllertemplatedescendantconfigMarks a deferred <template> child whose content is mounted into the container on demand.

CSS Classes

ClassRoleApplies toDescription
.z-stickyrootz-stickyRoot class for a sticky element, also styled on the z-sticky host; creates the positioning and stacking context.
.z-sticky-fixedstate.z-stickyState class applied while the element is fixed; zeroes its margin so the fixed position matches the layout slot.
.z-sticky-placeholderelement.z-stickySpacer inserted after the element while it is fixed to preserve the layout slot; pointer events are disabled so content beneath stays clickable.

Accessibility

  • The layout placeholder is marked aria-hidden="true" and hidden when not in use, so assistive technology ignores it.