Sticky
Pins content to the top or bottom of its scroll container and tells you when it is stuck, optionally hiding it while the reader scrolls down.
Attributes
| Name | Type | Default | Description |
|---|---|---|---|
edge | StickyEdge | top | The edge of the scroll container the content sticks to. |
hide-on-scroll | boolean | false | Slides the stuck content out of view while the reader scrolls down, and back in on the way up. |
Slots
| Name | Description |
|---|---|
(default) | Content to keep in view: a toolbar, tabs, a table header, a section heading. |
Events
| Name | Type | Description |
|---|---|---|
stuck-change | CustomEvent<{ stuck: boolean }> | Fired when the element becomes stuck to its edge or leaves it. |
retract-change | CustomEvent<{ retracted: boolean }> | Fired when hide-on-scroll slides the element out of view or back in. |
CSS parts
Shadow DOM styling hooks used with ::part(name). Prefer CSS custom properties when they cover the change.
| Name | Description |
|---|---|
surface | Box wrapping the assigned default slot: it draws the padding, background and shadow around the slotted content, does not style inside it, and slides out of view while retracted. |
CSS custom properties
Grouped by semantic target and state from --c2-<component>__<target>__<state>--<property>. Click a group to collapse it; click a name to copy it.
| Name | Type | Default | Description |
|---|---|---|---|
--c2-sticky--position | string | sticky | sticky pins the element; static turns pinning off, e.g. under a breakpoint. |
--c2-sticky--offset | pixel | 0px | Distance kept from the edge, e.g. the height of a sticky header above. |
--c2-sticky--z-index | number | 10 | |
--c2-sticky--background | color | transparent | |
--c2-sticky--box-shadow | box-shadow | none | |
--c2-sticky--padding | padding | 0px | |
--c2-sticky--border-radius | pixel | 0px | |
--c2-sticky--transition-duration | time | 200ms | Duration of the stuck and retract transitions. |
--c2-sticky__stuck--background | color | #ffffff | Background while stuck, so scrolled content does not show through. |
--c2-sticky__stuck--box-shadow | box-shadow | 0 1px 3px rgba(0, 0, 0, 0.18) | Shadow while stuck, separating the surface from the content beneath it. |
--c2-sticky__stuck--backdrop-filter | backdrop-filter | none | Backdrop filter while stuck, e.g. blur(12px) with a translucent stuck background. |