Skip to content

Backtop 回到顶部

Backtop 用于返回页面顶部。VISTA B 直接使用 Element Plus 的 el-backtop,显示区域固定为 40px * 40px,默认选用上箭头样式。

基础用法

滚动页面后,可以在页面右下角看到回到顶部按钮。点击按钮会触发组件内置的平滑返回顶部行为。

Scroll down to see the bottom-right button.

基础用法与 Element Plus 官方示例一致,默认监听页面滚动。

viewport
vue
<template>
  Scroll down to see the bottom-right button.
  <el-backtop :right="100" :bottom="100" />
</template>

自定义内容

默认显示区域固定为 40px * 40px,内部内容可以通过默认插槽自定义。

自定义内容

可替换为文字、图标或品牌化样式,但容器尺寸保持固定。

viewport
UP
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滚动高度达到该值时才显示number200
right控制显示位置,距离页面右侧的距离number40
bottom控制显示位置,距离页面底部的距离number40

Backtop 事件

事件名说明回调参数
click点击按钮触发的事件Function

Backtop 插槽

插槽说明
default自定义默认内容

HOMEVISTA 设计规范