小程序 返回顶部

<!-- 固定按钮 -->

        <image class="fixd-top {{showtop?'showtoppic':''}}" src="../../images/icon/top.png" bindtap="goTop"></image>

.fixd-top {

  width: 88rpx;

  height: 88rpx;

  display: block;

  position: fixed;

  bottom: 60rpx;

  opacity: 0;

  right: -600rpx;

  transition: all 0.8s ease-in-out;

  z-index: 22;

}

.showtoppic {

  opacity: 1;

  right: 54rpx;

  transition: all 0.6s ease-in-out;

}

 

 

data:{

   showtop: false, //返回顶部

}

 

    // 页面滚动

    onPageScroll(e) {

        if (e.scrollTop >= 110) {

            this.setData({

                showtop: true

            })

        } else {

            this.setData({

                showtop: false

            })

        }

    },

 

    // 返回顶部

    goTop: function (e) {

        wx.pageScrollTo({

            scrollTop: 0

        })

    },