BackTop 回到顶部请使用手机扫码体验

用于较长的页面快捷回到顶部的组件。

基本用法

  1. html
    <nut-backtop>
  2. </nut-backtop>

设置出现位置

  1. html
    <nut-backtop
  2. :distance="400"
  3. >
  4. </nut-backtop>

无动画

  1. html
    <nut-backtop :bottom="120" :is-animation="false" @click="handleClick">
  2. <div
  3. style="background-color: rgb(0, 0, 0);
  4. color: rgb(255, 255, 255);
  5. display: flex;
  6. height: 44px;
  7. width: 44px;
  8. align-items: center;
  9. justify-content: center;"
  10. >无</div>
  11. </nut-backtop>

自定义样式

  1. html
    <nut-backtop :bottom="70" @click="handleClick">
  2. <div
  3. style="background-color: rgb(0, 0, 0);
  4. color: rgb(255, 255, 255);
  5. display: flex;
  6. height: 44px;
  7. width: 44px;
  8. align-items: center;
  9. justify-content: center;"
  10. >Top</div>
  11. </nut-backtop>

“页面垂直方向滚动高度”后出现

click事件

  1. html
    <nut-backtop
  2. @click="onClick"
  3. >
  4. </nut-backtop>
  1. javascript
    export default {
  2. methods: {
  3. onClick() {
  4. console.log("触发回到顶部按钮")
  5. }
  6. }
  7. };

设置样式

  1. html
    <nut-backtop
  2. :bottom="20"
  3. :right="20"
  4. :z-index="10"
  5. >
  6. </nut-backtop>

设置动画持续时间

  1. html
    <nut-backtop
  2. :duration="1000"
  3. >
  4. </nut-backtop>

Prop

字段说明类型默认值
distance“页面垂直方向滚动高度”后出现Number200
is-animation是否有动画,和duration参数互斥Booleantrue
duration设置动画持续时间Number1000
z-index设置层级Number1111
el-id设置滚动事件监听的容器idString-
right设置离页面右边距离Number30
bottom设置离页面底部距离Number30

常见问题 : 滚动监听对象默认为window对象,开发者页面布局高度100%布局场景下,请采用此参数el-id

Event

字段说明回调参数
click按钮点击时触发-

BackTop 回到顶部 - 图1