html

<view class="top" :style="{'display':(flag===true? 'block':'none')}">
  <uni-icons class="topc" type="arrowthinup" size="50" @click="top"></uni-icons>
</view>
js

data() {
      return {
           flag:false
        }
},
methods: {
    top() { //回到顶部
        uni.pageScrollTo({
            scrollTop: 0,
            duration: 300
        });
    },
    onPageScroll(e){ //根据距离顶部距离是否显示回到顶部按钮
        if(e.scrollTop>600){ //当距离大于600时显示回到顶部按钮
            this.flag=true
        }else{ //当距离小于600时隐藏回到顶部按钮
            this.flag=false
        }
    },
}
css

/* 回到顶部 */
    .top {
        position: relative;
        display: none; /* 先将元素隐藏 */
    }
 
    .topc {
        position: fixed;
        right: 0;
        background: #F0F0F0;
        top: 70%;
        height: 50px;
        line-height: 50px;
    }
 
uni-app 最美的回到顶部

可以自已换成自已的图片,在CSS上再设一下透明度

相关文章:

  • 2021-08-16
  • 2022-12-23
  • 2021-07-23
  • 2021-12-05
  • 2022-01-01
  • 2022-01-01
  • 2021-10-05
  • 2021-09-18
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-03-04
  • 2021-12-03
  • 2022-12-23
  • 2021-08-09
相关资源
相似解决方案