当前位置:网站首页>Wechat applet slides to the top
Wechat applet slides to the top
2022-06-10 15:05:00 【yechaoa】
effect :
Click the icon in the lower right corner of the above figure to slide to the top . It's very simple , But there are some small details .
1. Determine the position of the icon button
Use the absolute position to fix it in the lower right corner .
wxml:
<icon type="download" size="45" color="#4caf50" bindtap='scrollTop'/>The official download icon is used here , Then I changed the color .
wxss:
icon[type=download] {
position: fixed;
bottom: 30px;
right: 20px;
transform: rotate(180deg);
}- In order not to follow the slide , Revised
positionbyfixed. - Originally, the arrow was downward , Use
transform: rotate(180deg)rotate 180 Degrees up .
2. The binding event
bindtap='scrollTop'
scrollTop: function() {
wx.pageScrollTo({
scrollTop: 0,
duration: 300
})
}, In the event , We used the official API wx.pageScrollTo, Two parameters , One is the sliding position , One is the execution time .
Here we are , The function of sliding to the top is simply realized .
3. Advanced
Why is there such a step , Because I found that whether the sliding distance is far or near , The execution duration is 300, Can it be optimized , It can .
WeChat page There is one of them. onPageScroll Method ( And onLoad Level ), Listen to user sliding page events . Then we can dynamically set the execution time according to the sliding distance .
Define the duration as a variable
data: {
scrollDuration: 500,
},Assign a value in the listening event
onPageScroll: function(e) {
console.log(e.scrollTop)
this.setData({
scrollDuration: e.scrollTop / 2
});
}- e.scrollTop Is the page sliding distance
- e.scrollTop / 2 Is the execution time , You can also set other values
- Official tip : Please avoid onPageScroll Too frequent execution in setData And so on - Operation of rendering layer communication .
Modify the sliding method
scrollTop: function() {
wx.pageScrollTo({
scrollTop: 0,
duration: this.data.scrollDuration
})
},ok, This is all done .
边栏推荐
- Cmake actual combat record (I)
- Golang []byte 转 File
- How to implement the association between interfaces in JMeter?
- Several reasons and solutions of virtual machine Ping failure
- Jaeger引入了对OpenTelemetry的原生支持
- As a programmer, is it really that important for the underlying principles?
- 【LogoDetection 数据集处理】(3)将训练集按照类别划分为多个文件夹
- MITM(中间人攻击)
- [logodetection data set processing] (2) draw the label box of the training set picture
- [cloud native | kubernetes] in depth RC, RS, daemonset, statefulset (VII)
猜你喜欢

Super practical operation! Calibration and registration of Kinect depth map and RGB camera for hands-on teaching

Hutool使用总结(VIP典藏版)

2022第十四届南京国际人工智能产品展会

CVPR 2022 Oral | SCI:实现快速、灵活与稳健的低光照图像增强

KaTeX问题 —— csdn编辑时中打出等号对齐的样式

At the early stage of product development, do you choose to develop apps or applets?

LeetCode_ 21 (merge two ordered linked lists)

详解OpenCV的函数filter2D(),并提醒大家它做的运算并不是卷积运算而是相关运算

Sanzi chess (implemented in C language)

【LogoDetection 数据集处理】(2)画出训练集图片的标注框
随机推荐
自媒体视频热门思路分享
LeetCode_ 20 (brackets match)
如何构建以客户为中心的产品蓝图:来自首席技术官的建议
Docker deploys a redis cluster
华为云SRE确定性运维介绍
Overview of cann interface calling process
如何实现erp外网连接?
One-way hash function
虚拟机ping不通的几种原因及解决办法
Sanzi chess (implemented in C language)
[logodetection dataset processing] (4) extract the logo area of each picture
Kubernetes 1.24:StatefulSet引进了maxUnavailable副本数
三子棋(c语言实现)
Insight Technology a été sélectionné dans le rapport panorama des fournisseurs d'analyse de l'amour et d'informatique de la vie privée et a été évalué comme représentant des fournisseurs de solutions
Ada Logics:CRI-O整体安全审计项目
Insight technology was selected into the "Aijian · privacy computing manufacturer panorama report" and was rated as a representative manufacturer of financial solutions
Remote monitoring and data acquisition solution
[cloud native | kubernetes] in depth RC, RS, daemonset, statefulset (VII)
As a programmer, is it really that important for the underlying principles?
Kubernetes 1.24: 避免为 Services 分配 IP 地址时发生冲突