Skip to content

BackTop 回到顶部 ​

滚动超过阈值后出现悬浮按钮,点击平滑回到顶部。

基础用法 ​

vue
<template>
  <div style="height:200vh">
    向下滚动页面,右下角会出现按钮
  </div>
  <KbBackTop />
</template>

演示

按钮固定定位在视口右下角,请向下滚动当前页面查看效果。

自定义阈值与位置 ​

vue
<template>
  <KbBackTop :visibility-height="400" :right="24" :bottom="24" />
</template>

指定滚动容器 ​

target 可传 CSS 选择器或元素,未传时监听窗口。

vue
<template>
  <div id="scroll-box" style="height:300px;overflow:auto">
    <div style="height:1200px">内容</div>
  </div>
  <KbBackTop target="#scroll-box" />
</template>

自定义内容 ​

vue
<template>
  <KbBackTop>
    <span>UP</span>
  </KbBackTop>
</template>

API ​

Props ​

属性类型默认值说明
visibilityHeightnumber200滚动超过该值后显示
targetstring | HTMLElement—滚动监听目标,默认窗口
rightnumber40距视口右侧距离(px)
bottomnumber40距视口底部距离(px)
durationnumber300动画时长(ms),0 表示直接跳转

事件 ​

事件参数说明
clickMouseEvent点击按钮