const app = getApp();
Page({
data:{
// top标签显示(默认不显示)
backTopValue:false
},
// 监听滚动条坐标
onPageScroll: function (e) {
//console.log(e)
var that = this
var scrollTop = e.scrollTop
var backTopValue = scrollTop > 500 ? true : false
that.setData({
backTopValue: backTopValue
})
},
// 滚动到顶部
backTop:function(){
// 控制滚动
wx.pageScrollTo({
scrollTop: 0
})
},
})
wxss
/*浮窗返回顶部*/
.backTop {
width: 80rpx;
height: 80rpx;
background: #fff;
position: fixed;
right: 20rpx;
bottom: 130rpx;
border-radius: 40rpx;
box-shadow: 0px 0px 3px #000;
line-height: 75rpx;
text-align: center;
}
.backTop text {
font-size: 35rpx;
}
/*浮窗返回顶部 结束*/
wxml
<!--浮窗 Top-->
<view class="backTop" bindtap='backTop' wx:if="{{backTopValue ==true}}"><text class='iconfont icon-top li-ico'></text></view>