Skip to content

BackTop 回到顶部

页面内容很长时,滚动到一定距离后可以显示回到顶部按钮,点击后可以回到顶部。

Tips
需要注意滚动元素是通过方法查找,不是传字符串

基础使用

使用 getTarget 属性指定滚动容器,默认为 window

BackTop1
vue
<template>
  <div>
    <ImBackTop :getTarget="gatTarget" right="20vh" bottom="8vh">
      <ImButton color="primary" shape="circle" size="68">
        <ImIcon name="vertical-align-top" size="40"></ImIcon>
      </ImButton>
    </ImBackTop>
    <div class="demo" id="scroll_id">
      <div class="inner">BackTop1</div>
    </div>
  </div>
</template>

<script setup>
function gatTarget() {
  return document.querySelector('#scroll_id');
}
</script>

API

以下是根据您提供的字段生成的API说明表格,格式为Markdown:

字段名类型描述
getTarget() => HTMLElement | null获取目标元素的方法
visibleHeightnumber滚动距离超过多少显示
zIndexnumber设置组件的z-index值
rightnumber | string距离右侧的距离
bottomnumber | string距离底部的距离

基于 MIT 协议发布