BackTop
Shows a return-to-top control for a page or an explicit scroll target after a threshold.
Import
Use <hui-back-top> after configuring uni-app easycom. Import public types and functions from @nscode/handy-uni. Ordinary Vue applications install the @nscode/handy-uni/web preview plugin.
Examples
Each example is standalone. Controls show the current value or event result on the page.
<template>
<view>
<hui-space direction="vertical" fill>
<hui-button custom-class="hui-space__item" @click="top = top === 0 ? 500 : 0"
>模拟滚动 / Simulate scroll</hui-button
>
<text class="hui-space__item">{{ top }} / {{ lastEvent }}</text>
<hui-back-top
custom-class="hui-space__item"
:scroll-top="top"
:target="target"
text="顶部 / Top"
@click="lastEvent = 'click'"
@visible-change="(value) => (lastEvent = String(value))"
/>
</hui-space>
</view>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const lastEvent = ref('尚无事件 / No event')
const top = ref(0)
const target = {
scrollTo: (value: number) => {
top.value = value
}
}
</script>
Props
| Prop | Type | Default | Details |
|---|---|---|---|
scrollTop | number | — | Page scroll position forwarded by the application. |
target | 'page' | BackTopTarget | 'page' | Page scrolling or an object exposing scrollTo(top, duration). |
visibilityHeight | number | 200 | Minimum scroll distance before automatic display. |
visible | boolean | undefined | Controlled visibility. |
right | number | 16 | Distance from the right edge in px. |
bottom | number | 100 | Distance from the bottom safe area in px. |
duration | number | 300 | Animation or display duration in milliseconds; see platform notes for zero. |
icon | string | 'top' | Icon registry name. |
text | string | — | Text content; NoticeBar also accepts a list. |
shape | BackTopShape | 'circle' | Visual shape. |
zIndex | number | 10 | Explicit stacking level. |
Root classes and styles use customClass and customStyle. Numbers representing dimensions use px; durations use ms unless explicitly documented.
Events
| Event | Arguments |
|---|---|
click | (event: unknown) |
visible-change | (visible: boolean) |
Controlled state only changes when the parent accepts its update event. Events with multiple words use kebab-case. Disabled or stale asynchronous actions do not emit a successful state change.
Slots
| Slot | Scope |
|---|---|
default | — |
Methods
None.
Types
BackTopTarget、BackTopShape、BackTopProps、BackTopEmits.
Platform notes
uni-app pages must forward e.scrollTop from onPageScroll through scroll-top. Inner targets expose scrollTo(top,duration). Ordinary Web can subscribe to page scrolling and unsubscribes during KeepAlive deactivation.
Device smoke checklist.