


There are two ways to return to the top of the mini program, namely:
(Learning recommendation: Programming Video)
1. Use the view form to return to the top
HTML:
<image src='../../img/button-top.png' class='goTop' hidden='{{!floorstatus}}' bindtap="goTop"></image>
CSS:
/* 返回顶部 */ .goTop{ height: 80rpx; width: 80rpx; position: fixed; bottom: 50rpx; background: rgba(0,0,0,.3); right: 30rpx; border-radius: 50%; }
JS:
// 获取滚动条当前位置 onPageScroll: function (e) { console.log(e) if (e.scrollTop > 100) { this.setData({ floorstatus: true }); } else { this.setData({ floorstatus: false }); } }, //回到顶部 goTop: function (e) { // 一键回到顶部 if (wx.pageScrollTo) { wx.pageScrollTo({ scrollTop: 0 }) } else { wx.showModal({ title: '提示', content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。' }) } },
2. Use scroll- Return to the top in view form
<image src='../../img/button-top.png' class='goTop' hidden='{{!floorstatus}}' bindtap="goTop"></image>
CSS:
/* 返回顶部 */ .goTop{ height: 80rpx; width: 80rpx; position: fixed; bottom: 50rpx; background: rgba(0,0,0,.3); right: 30rpx; border-radius: 50%; }
JS:
data:{ topNum: 0 } // 获取滚动条当前位置 scrolltoupper:function(e){ console.log(e) let t = e.detail.scrollTop; if (t > 100 && !this.data.floorstatus) { // 避免重复setData this.setData({ floorstatus: true }); } if(t <= 100 && this.data.floorstatus){ this.setData({ floorstatus: false }); } }, //回到顶部 goTop: function (e) { // 一键回到顶部 this.setData({ topNum: this.data.topNum = 0 }); },
Related recommendations:小program development tutorial
The above is the detailed content of What are the two ways to return to the top of the mini program?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

WebStorm Mac version
Useful JavaScript development tools
