Skip to content

Backtop 返回顶部

返回页面顶部的操作按钮,当页面滚动到一定高度时自动显示。

基础用法

滑动页面即可看到右下方的返回顶部按钮,默认在滚动超过 200px 时显示。

滚动页面查看返回顶部按钮(第 1 段)

滚动页面查看返回顶部按钮(第 2 段)

滚动页面查看返回顶部按钮(第 3 段)

滚动页面查看返回顶部按钮(第 4 段)

滚动页面查看返回顶部按钮(第 5 段)

滚动页面查看返回顶部按钮(第 6 段)

滚动页面查看返回顶部按钮(第 7 段)

滚动页面查看返回顶部按钮(第 8 段)

滚动页面查看返回顶部按钮(第 9 段)

滚动页面查看返回顶部按钮(第 10 段)

滚动页面查看返回顶部按钮(第 11 段)

滚动页面查看返回顶部按钮(第 12 段)

滚动页面查看返回顶部按钮(第 13 段)

滚动页面查看返回顶部按钮(第 14 段)

滚动页面查看返回顶部按钮(第 15 段)

滚动页面查看返回顶部按钮(第 16 段)

滚动页面查看返回顶部按钮(第 17 段)

滚动页面查看返回顶部按钮(第 18 段)

滚动页面查看返回顶部按钮(第 19 段)

滚动页面查看返回顶部按钮(第 20 段)

自定义位置和内容

通过 position 设置按钮位置,使用默认插槽自定义按钮内容。

自定义返回顶部按钮(第 1 段)

自定义返回顶部按钮(第 2 段)

自定义返回顶部按钮(第 3 段)

自定义返回顶部按钮(第 4 段)

自定义返回顶部按钮(第 5 段)

自定义返回顶部按钮(第 6 段)

自定义返回顶部按钮(第 7 段)

自定义返回顶部按钮(第 8 段)

自定义返回顶部按钮(第 9 段)

自定义返回顶部按钮(第 10 段)

指定滚动容器

通过 target 指定需要监听滚动的容器。

容器内滚动内容(第 1 段)

容器内滚动内容(第 2 段)

容器内滚动内容(第 3 段)

容器内滚动内容(第 4 段)

容器内滚动内容(第 5 段)

容器内滚动内容(第 6 段)

容器内滚动内容(第 7 段)

容器内滚动内容(第 8 段)

容器内滚动内容(第 9 段)

容器内滚动内容(第 10 段)

容器内滚动内容(第 11 段)

容器内滚动内容(第 12 段)

容器内滚动内容(第 13 段)

容器内滚动内容(第 14 段)

容器内滚动内容(第 15 段)

容器内滚动内容(第 16 段)

容器内滚动内容(第 17 段)

容器内滚动内容(第 18 段)

容器内滚动内容(第 19 段)

容器内滚动内容(第 20 段)

容器内滚动内容(第 21 段)

容器内滚动内容(第 22 段)

容器内滚动内容(第 23 段)

容器内滚动内容(第 24 段)

容器内滚动内容(第 25 段)

容器内滚动内容(第 26 段)

容器内滚动内容(第 27 段)

容器内滚动内容(第 28 段)

容器内滚动内容(第 29 段)

容器内滚动内容(第 30 段)

Backtop API

Props

参数说明类型默认值
target滚动目标元素选择器string''(window)
visibilityHeight显示阈值(px)number200
position按钮位置'top-right' | 'top-left' | 'bottom-right' | 'bottom-left''bottom-right'
right右侧偏移(px)number40
bottom底部偏移(px)number40

Events

事件名说明回调参数
click点击时(event: MouseEvent)
show按钮显示时
hide按钮隐藏时

Slots

插槽名说明
default自定义按钮内容(默认显示箭头图标)

基于 MIT 许可发布