• 微信
您当前的位置: 首页> 小程序>

小程序返回顶部top滚动

作者:Alpha时间:2018-10-06 阅读数:3376 +人阅读

js部分:

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
      })
  },
})

css部分:

/*浮窗返回顶部*/ 
.backTop{width: 60rpx; height:60rpx;background: #fff;position: fixed; right: 20rpx ; bottom: 130rpx; border-radius: 30rpx;box-shadow: 0px 0px 3px #000; line-height: 60rpx; text-align: center} 
.backTop text{font-size: 45rpx; }

html部分:

<!--浮窗 Top--> 
<view class="backTop" bindtap='backTop' wx:if="{{backTopValue ==true}}"><text class='iconfont icon-top li-ico'></text></view>


本站所有文章、数据、图片均来自互联网,一切版权均归源网站或源作者所有。

如果侵犯了你的权益请来信告知我们删除。邮箱:595397166@qq.com

标签: 小程序

阿尔法

软件开发工程师#全栈工程师

{include file=foot.html}