当前位置:网站首页>Applet Click to return to the top 2 methods
Applet Click to return to the top 2 methods
2022-06-25 19:33:00 【Bin daotianxia】
1. Applicable scenario : Page not used scroll-view Components
( I have been looking for this method for a long time )
wxml:( Find the picture yourself , I won't give it )
<image src='{
{img_url}}mp/[email protected]' class='goTop' hidden='{
{!floorstatus}}' bindtap="goTop"></image>wxss:
.goTop{
height: 80rpx;
width: 80rpx;
position: fixed;
bottom: 50rpx;
right: 30rpx;
border-radius: 50%;
}js( On the blackboard ):
data Give me an initial value :floorstatus: true,
// Get the current position of the scroll bar
onPageScroll: function (e) {
console.log(e)
if (e.scrollTop > 150) {
this.setData({
floorstatus: true
});
} else {
this.setData({
floorstatus: false
});
}
},
// Back to the top
goTop: function (e) { // One click back to the top
if (wx.pageScrollTo) {
wx.pageScrollTo({
scrollTop: 0
})
} else {
wx.showModal({
title: ' Tips ',
content: ' Current wechat version is too low , This feature is not available , Please upgrade to the latest wechat version and try again .'
})
}
},2. Page used scroll-view Components
The page uses this component , Then you are free , The official documentation of the small program is very clear , Get scroll bar position . Ha ha ha
wxml:
<scroll-view scroll-y scroll-top='{
{topNum}}' bindscroll="scrolltoupper">
<image src='../../img/button-top.png' class='goTop' hidden='{
{!floorstatus}}' bindtap="goTop"></image>css: css ditto
.goTop{
height: 80rpx;
width: 80rpx;
position: fixed;
bottom: 50rpx;
right: 30rpx;
border-radius: 50%;
}js:
data:{
topNum: 0
}
// Get the current position of the scroll bar
scrolltoupper:function(e){
console.log(e)
if (e.detail.scrollTop > 100) {
this.setData({
floorstatus: true
});
} else {
this.setData({
floorstatus: false
});
}
},
// Back to the top
goTop: function (e) { // One click back to the top
this.setData({
topNum: this.data.topNum = 0
});
},
2 This method has covered all the scenes . Choose one according to your situation .
Finish off work ! Pay attention
边栏推荐
- Network security detection and prevention exercises (III)
- DataX script task development record
- Many varieties of EA can be used
- R language plot visualization: plot visualization of two-dimensional histogram contour (basic 2D histogram contour)
- Using flex to implement the Holy Grail layout is as simple as that
- SEO outsourcing reliable company, enterprise SEO outsourcing company which reliable?
- PHP synchronizes website content to hundreds of websites to improve SEO ranking
- 二、HikariCP獲取連接流程源碼分析二
- On location and scale in CNN
- 三、HikariCP获取连接流程源码分析三
猜你喜欢

On Oracle full stack virtual machine -- graalvm

削足适履 - 谈谈赛道上的坡道改造

ECS 7-day practical training camp (Advanced route) -- day03 -- ecs+slb load balancing practice

Print 1 cute every 100 milliseconds ~ with a running lantern effect

Laravel validation rule followed Role of auth:: id()

最新数据挖掘赛事方案梳理!

什么是算子?

【C语言练习——打印上三角及其变形(带空格版)】

Tiger Dao VC products are officially launched, a powerful supplement to seektiger ecology

DARKHOLE 2
随机推荐
Overview and trend analysis of China's foreign direct investment industry in 2020 [figure]
Embark on a new journey and reach the world with wisdom
Laravel validation rule followed Role of auth:: id()
QQ robot: self forbidden words management of group members [latest beta2 version]
SEO outsourcing reliable company, enterprise SEO outsourcing company which reliable?
Paddleocr learning (II) paddleocr detection model training
On Oracle full stack virtual machine -- graalvm
Network security detection and prevention test questions (4)
R language uses the model of DALEX package_ The profile function interprets the relationship between a continuous feature and the target value Y in multiple classification models based on the conditio
Vulnhub range the planes: mercury
Mail monitoring cloud script execution progress
JS get data
削足适履 - 谈谈赛道上的坡道改造
Validation of TTF font by validator of laravel
What are Baidu collection skills? 2022 Baidu article collection skills
Leetcode-101-symmetric binary tree
LeetCode-78-子集
为什么生命科学企业都在陆续上云?
From the perspective of the core competitiveness of ABT, the Internet giant, who fell first
QQ机器人:群成员自我禁言管理【最新beta2版本】