Sticky
CSS sticky placement at either edge. An intersection observer is created only when change is observed.
Import
With uni-app easycom, use hui-sticky。 Standalone Vue imports @nscode/handy-uni/web HuiSticky or installs the preview plugin.
Examples
Interaction and event results
Interact with the control. The latest event and its full payload are shown below. Popup selectors commit only after confirmation; cancellation keeps the previous value.
vue
<script setup lang="ts">
import { ref } from 'vue'
const result = ref('')
function event0(arg0: unknown) {
result.value = 'change' + ': ' + JSON.stringify([arg0])
}
</script>
<template>
<view>
<hui-sticky :offset-top="12" @change="event0"
><text>吸附内容 / Sticky content</text></hui-sticky
>
<text aria-live="polite">{{ result }}</text>
</view>
</template>
Props
| Property | Type | Default | Description |
|---|---|---|---|
position | "top" | "bottom" | undefined | 'top' | Sticky edge, top or bottom. |
offset-top | number | undefined | 0 | Top offset in pixels; include custom navigation height. |
offset-bottom | number | undefined | 0 | Bottom offset in pixels. |
safe-area-inset-bottom | boolean | undefined | false | Add bottom safe-area spacing. |
z-index | number | undefined | — | Explicit layer index; otherwise assigned by the page layer stack. |
disabled | boolean | undefined | false | Disable user interaction, including inherited form state. |
custom-class | string | undefined | '' | Additional root classes. |
custom-style | string | CSSProperties | undefined | — | Additional root styles. |
Events
| Event | Parameters | Description |
|---|---|---|
change | (isStuck: boolean) | Reports change with the arguments shown in the example. |
Slots
| Slot | Description |
|---|---|
default | Default content. |
Methods
| Method | Signature |
|---|
Types
StickyProps、StickyEmits。 Public types are exported from the package entry.
Platform notes
| Scope | Behavior and validation limits |
|---|---|
| Shared implementation | Uses platform measurements for sticky positions. Forward page scrolling as documented; the component does not import page lifecycle hooks. |
| Device checks pending | Check navigation offsets, container boundaries, page changes and content resizing; verify positions while scrolling on devices. |
See examples/uni-demo/smoke/Sticky.md for the checklist. Unit tests do not replace device acceptance.