layoutcontroller
z-stickySticky
Sticks an element to the viewport edge on scroll, with start/end boundaries, show-on-up reveal, overflow handling, and native-sticky fallback.
Attributes
| Attribute | Type | Default | Description |
|---|---|---|---|
position | 'top' | 'bottom' | 'top' | Edge the element sticks to: top once scrolled past its natural position, or bottom of the viewport. |
offset | string | '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-end | string | '0' | Distance from the opposite edge, used when computing overflow and the bottom sticking position; accepts the same syntax as offset. |
start | string | '' | 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. |
end | string | '' | 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-up | boolean | false | Only sticks while scrolling up; scrolling down hides the fixed element, playing the leave animation when animation is set. |
overflow-flip | boolean | false | When 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. |
animation | string | '' | Animation preset played when the fixed element enters or leaves (with show-on-up, or when scrolling below its natural position). |
duration | number | 150 | Animation duration in milliseconds; non-finite or negative values fall back to 150. |
media | string | '' | 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-offset | string | '' | 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-target | string | '' | CSS selector for a descendant that receives the active/inactive classes instead of the host. |
Inherited from Base
| Attribute | Type | Default | Description |
|---|---|---|---|
cls | string | '' | Adds classes to named parts as key: classes pairs; a plain string targets the default part. |
stl | string | '' | 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
| Key | Default class | cls | stl | Description |
|---|---|---|---|---|
active | z-active | yes | no | Class applied while the element is sticking (or to sel-target); the default cls target for this component. |
below | z-sticky-below | yes | no | Class applied once the page has scrolled past the element's natural position. |
fixed | z-sticky-fixed | yes | no | Class applied while the element is position: fixed rather than native sticky. |
inactive | — | yes | no | Class applied while the element is not sticking; empty by default. |
Events
| Event | Detail | Flags | Description |
|---|---|---|---|
z-sticky:active | { fixed: boolean; below: boolean; scroll: number; target: HTMLElement } | bubbles | Fires 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 } | bubbles | Fires 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 } | bubbles | Fires when the element stops sticking, with the same detail shape as active. |
z-sticky:mount · from Controller | Record<string, unknown> | bubbles | Fires when deferred template content is mounted into the container. |
Methods
| Signature | Description |
|---|---|
isActive(): boolean | Returns whether the element is currently sticking. |
isBelow(): boolean | Returns whether the page has scrolled past the element's natural position. |
isFixed(): boolean | Returns whether the element is currently position: fixed (as opposed to native sticky or static). |
refresh(): void | Re-measures the element and viewport and re-syncs the sticky state. |
Data Hooks
| Attribute | Values | Applies to | Role | Description |
|---|---|---|---|---|
data-fn · from Controller | template | descendant | config | Marks a deferred <template> child whose content is mounted into the container on demand. |
CSS Classes
| Class | Role | Applies to | Description |
|---|---|---|---|
.z-sticky | root | z-sticky | Root class for a sticky element, also styled on the z-sticky host; creates the positioning and stacking context. |
.z-sticky-fixed | state | .z-sticky | State class applied while the element is fixed; zeroes its margin so the fixed position matches the layout slot. |
.z-sticky-placeholder | element | .z-sticky | Spacer 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"andhiddenwhen not in use, so assistive technology ignores it.