Skip to content

Backtop

Button for returning to the top of the page.

Component Type

Basic Usage

Since backtop needs to monitor page scroll position in real-time, it usually requires getting scroll distance in the page's onPageScroll lifecycle, then passing it to the component via scroll-top.

html
<wd-backtop :scroll-top="scrollTop"></wd-backtop>
ts
import { onPageScroll } from '@dcloudio/uni-app'
import { ref } from 'vue'

const scrollTop = ref(0)

onPageScroll((event) => {
  scrollTop.value = event.scrollTop
})

Component Variant

Shape and Text

Switch between circle or square button via shape, display button text via text.

html
<wd-backtop :scroll-top="scrollTop" shape="square" text="TOP"></wd-backtop>

Custom Icon

Default slot can replace button internal content.

html
<wd-backtop :scroll-top="scrollTop">
  <text>TOP</text>
</wd-backtop>

Component Style

Custom Display Distance

Set the scroll distance threshold to show button via top.

html
<wd-backtop :scroll-top="scrollTop" :top="600"></wd-backtop>

Custom Style

Adjust button and icon styles via custom-style and icon-style.

html
<wd-backtop :scroll-top="scrollTop" custom-style="background: #007aff;color:white;" icon-style="color: white;"></wd-backtop>

Custom Scroll Duration

Set return to top scroll duration via duration, unit is milliseconds.

html
<wd-backtop :scroll-top="scrollTop" :duration="1000"></wd-backtop>

Backtop Attributes

ParameterDescriptionTypeDefault Value
scroll-topPage scroll distancenumber-
textButton textstring-
topShow button when scroll distance exceeds this value, unit is pxnumber300
durationReturn to top scroll time, unit is msnumber100
z-indexComponent z-indexnumber10
icon-styleCustom icon stylestring''
shapeButton shape, optional values are circle, squarestringcircle
bottomDistance from screen bottom, unit is pxnumber100
rightDistance from screen right, unit is pxnumber20
custom-styleCustom root node stylestring''
custom-classCustom root node style classstring''

Backtop Slots

NameDescription
defaultCustom button content

主题定制

CSS 变量

组件提供了下列 CSS 变量,可用于自定义样式,使用方法请参考 ConfigProvider 全局配置

名称默认值描述
--wot-backtop-bg$filled-oppo背景色
--wot-backtop-border-color$border-main边框颜色
--wot-backtop-width$n-48按钮宽度
--wot-backtop-height$n-48按钮高度
--wot-backtop-radius$radius-main方形模式圆角
--wot-backtop-radius-circle$radius-radius-full圆形模式圆角
--wot-backtop-color$icon-main按钮图标颜色
--wot-backtop-icon-size$n-20按钮图标尺寸
--wot-backtop-text-font-size$typography-label-size-main文本字号
--wot-backtop-text-color$text-main文本颜色
--wot-backtop-text-line-height$typography-label-line--height-size-main文本行高
--wot-backtop-z-index100组件层级

Source Code

Documentation
Component

Released under the MIT License.

Released under the MIT License.