Skip to content

BackTop 返回顶部

预览
01:38

组件名:rice-back-top

一键返回顶部

平台兼容性

uni-app x

AndroidiOS鸿蒙Next微信小程序h5

基础使用

由于小程序不支持在组件中监听页面滚动事件,所以 scroll-top 参数在小程序端是必传的,APP和H5端可以不传
在 iOS端 目前需要携带 parentId 参数,值为 <scroll-view id="backId"></scroll-view>中 id的值

html
<!-- #ifdef APP -->
<scroll-view id="backId">
  <!-- #endif -->
  <rice-back-top :scroll-top="scrollTop"  parentId="backId"></rice-back-top> 
<!-- #ifdef APP -->
</scroll-view>
<!-- #endif -->

API

Props

属性名类型说明默认值
scroll-topNumber页面的滚动距离,通过onPageScroll生命周期获取,仅支持小程序-
offsetNumber滚动条滑动多少距离时显示组件,默认400px-
modeString样式类型,可选值:round、half-roundround
parent-idStringscroll-view 或 list 组件的 id-
rightString|Number距离页面右侧的距离,默认 20px-
bottomString|Number距离页面底部的距离,组件内部会自动避开底部tabbar和安全区域,默认 100px-
durationNumber滚动到顶部所需的时间,单位ms,默认100ms-
iconString按钮内部的图标,设置为空字符串就不显示图标,默认值back-top-
icon-sizeString|Number图标的大小-
text-colorString图标/文字的颜色-
textString按钮内部的文字,优先级低于icon,图标和文字同时只能显示一个(使用自定义插槽除外)-
text-sizeString按钮内部文字的大小,默认13px-
widthString|Number宽度,默认45px-
heightString|Number高度,默认45px-
radiusString|Number圆角值,默认和width一致-
zoomBoolean是否启用缩放动画-
bg-colorString按钮背景颜色-
z-indexNumberz-index的值,默认998-
custom-styleObject自定义按钮样式-

Events

事件名说明回调参数
click点击时触发(event:UniPointerEvent)
名称说明
default默认内容

类型定义

组件导出如下类型

ts
// 组件类型
const backTopRef = ref<RiceBackTopComponentPublicInstance | null>(null)