Backtop 回到顶部
Backtop 用于返回页面顶部。VISTA B 直接使用 Element Plus 的 el-backtop,显示区域固定为 40px * 40px,默认选用上箭头样式。
基础用法
滚动页面后,可以在页面右下角看到回到顶部按钮。点击按钮会触发组件内置的平滑返回顶部行为。
vue
<template>
Scroll down to see the bottom-right button.
<el-backtop :right="100" :bottom="100" />
</template>自定义内容
默认显示区域固定为 40px * 40px,内部内容可以通过默认插槽自定义。
vue
<template>
Scroll down to see the bottom-right button.
<el-backtop :bottom="100">
<div
style="
height: 100%;
width: 100%;
background-color: var(--el-bg-color-overlay);
box-shadow: var(--el-box-shadow-lighter);
text-align: center;
line-height: 40px;
color: #1989fa;
"
>
UP
</div>
</el-backtop>
</template>点击事件
click 是 Backtop 的官方事件,点击按钮时触发。返回顶部行为由组件自身处理,事件只用于统计、反馈或业务扩展。
vue
<template>
<el-backtop @click="handleClick" />
</template>
<script setup>
const handleClick = (event) => {
console.log('backtop clicked', event)
}
</script>API
Backtop 属性
| 属性 | 说明 | 类型 | 默认值 |
|---|---|---|---|
target | 触发滚动的对象,传入 CSS 选择器 | string | 空 |
visibility-height | 滚动高度达到该值时才显示 | number | 200 |
right | 控制显示位置,距离页面右侧的距离 | number | 40 |
bottom | 控制显示位置,距离页面底部的距离 | number | 40 |
Backtop 事件
| 事件名 | 说明 | 回调参数 |
|---|---|---|
click | 点击按钮触发的事件 | Function |
Backtop 插槽
| 插槽 | 说明 |
|---|---|
default | 自定义默认内容 |

