当前位置:网站首页>Customize the left sliding button in the line in the applet, which is similar to the QQ and Wx message interface
Customize the left sliding button in the line in the applet, which is similar to the QQ and Wx message interface
2022-07-05 10:19:00 【huxiaoxiao.】
Usually in use QQ perhaps WX Chat , Slide an item left in the message list , Several operation buttons will appear , What's the top , Mark unread and so on , Let's use the native applet to realize this function
wxml part
<!-- moveTarget It mainly records the current sliding or closing state -->
<view class="list-group {
{moveTarget=='move-box-'+index?('item-move'+(btnList.length>3?3:btnList.length)):''}}"
mut-bind:touchmove="touchListMove"
mut-bind:touchstart="touchListStrat"
data-target="move-box-{
{index}}"
wx:for="{
{reportDataList}}" wx:key="index">
<view class="box">
{
{item}}
</view>
<!-- btnList, The button array after sliding left -->
<view class="btn-group" wx:if="{
{btnList.length>0}}">
<view wx:for="{
{btnList}}" wx:key="index" class="btn" bindtap="tapBtn"
data-btnindex="{
{index}}">
{
{item}}
</view>
</view>
</view>
1.moveTarget
Defined in the tag data-target="move-box-{ {index}}" , For example, there are ten boxes in the page , You slide the first , Then the corresponding result is move-box-0, Then give... In the method moveTarget assignment data-target , When the two are the same , The corresponding box can slide , If you don't make this limitation , It will cause a box to slide , All boxes move together
2. mut-bind:touchmove="touchListMove" mut-bind:touchstart="touchListStrat"
Corresponding sliding start and sliding end methods :mut-bind , I don't quite understand the detailed meaning , Maybe one method works, and the other also works , Interested in Baidu for a while
3.{ {moveTarget=='move-box-'+index?('item-move'+(btnList.length>3?3:btnList.length)):''}}
Here is the corresponding (1) What it says is , If equal , Find the corresponding box , Add the following class name , The style corresponding to the class name specifies the width of sliding to the left
wxss part
/* Suppose the width of an operation button is 166rpx,item-move1 Represents the style of an operation button , And so on */
.list-group.item-move3{
transform: translateX(-500rpx);
}
.list-group.item-move2{
transform: translateX(-332rpx);
}
.list-group.item-move1{
transform: translateX(-166rpx);
}
.list-group {
position: relative;
height: 100rpx;
line-height: 100rpx;
width: 100%;
background-color: #f0f0f0;
margin-bottom: 10rpx;
transition: all .6s ease-in-out 0s;
}
/* Position the operation button on the right side of the box , Remember to add transform: translateX(100%); */
.btn-group {
position: absolute;
right: 0;
top: 0;
width: 500rpx;
height: 100%;
display: flex;
flex-direction: row;
transform: translateX(100%);
}
.btn-group .btn{
width: 166.5rpx;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
js part
All the data here is customized by me , Actually, it is possible to obtain data in the background
// pages/index/component/index.js
Component({
/**
* Initial data of the page
*/
data: {
reportDataList: [' The box 1',' The box 2'], // Page box array
btnList: [' Button 1',' Button 2',' Button 3'], // Operation button array
moveStartX: 0, // Sliding distance
moveTarget: '', // Slide control
},
// Component method Center
methods: {
// Slide start
touchListStrat(e) {
this.setData({
moveStartX: e.touches[0].pageX
})
},
// Slip end
touchListMove(e) {
let moveEndX = e.touches[0].pageX;
let moveStartX = this.data.moveStartX;
let btnList = this.data.btnList;
if (btnList.length>0) {
let size = Math.abs(moveEndX - moveStartX);
if (moveEndX < moveStartX) {
if (size > 20) {
this.setData({
moveTarget: e.currentTarget.dataset.target
})
}
} else {
this.setData({
moveTarget: ''
})
}
}
},
// Click the in line button
tapBtn(e) {
let btnindex = e.currentTarget.dataset.btnindex;
// Button click events can be defined here
// When you click the button, let moveTarget It's empty , In this way, you cannot find the box you are currently sliding , So after clicking, the slide will return to its original state
this.setData({
moveTarget: ""
})
}
}
})
The effect has been roughly achieved
边栏推荐
- 请问postgresql cdc 怎么设置单独的增量模式呀,debezium.snapshot.mo
- isEmpty 和 isBlank 的用法区别
- 程序员搞开源,读什么书最合适?
- Swift uses userdefaults and codable to save an array of class objects or structure instances
- 伪类元素--before和after
- Universal double button or single button pop-up
- 【JS】数组降维
- 驱动制造业产业升级新思路的领域知识网络,什么来头?
- Atcoder beginer contest 254 "e BFS" f st table maintenance differential array GCD "
- Applet image height adaptation and setting text line height
猜你喜欢
AtCoder Beginner Contest 258「ABCDEFG」
WorkManager學習一
自动化规范检查软件如何发展而来?
如何判断线程池已经执行完所有任务了?
Workmanager Learning one
AtCoder Beginner Contest 254「E bfs」「F st表维护差分数组gcd」
《微信小程序-基础篇》小程序中的事件与冒泡
Advanced opencv:bgr pixel intensity map
【黑马早报】罗永浩回应调侃东方甄选;董卿丈夫密春雷被执行超7亿;吉利正式收购魅族;华为发布问界M7;豆瓣为周杰伦专辑提前开分道歉...
Universal double button or single button pop-up
随机推荐
钉钉、企微、飞书学会赚钱了吗?
[C language] the use of dynamic memory development "malloc"
如何判断线程池已经执行完所有任务了?
Dedecms website building tutorial
Applet image height adaptation and setting text line height
A high density 256 channel electrode cap for dry EEG
历史上的今天:第一本电子书问世;磁条卡的发明者出生;掌上电脑先驱诞生...
学习笔记6--卫星定位技术(上)
Swift saves an array of class objects with userdefaults and nssecurecoding
微信小程序中,从一个页面跳转到另一个页面后,在返回后发现页面同步滚动了
Zblogphp breadcrumb navigation code
Cerebral cortex: directed brain connection recognition widespread functional network abnormalities in Parkinson's disease
Jupiter notebook shortcut key
What is the origin of the domain knowledge network that drives the new idea of manufacturing industry upgrading?
Today in history: the first e-book came out; The inventor of magnetic stripe card was born; The pioneer of handheld computer was born
Interview: how does the list duplicate according to the attributes of the object?
vscode的快捷键
Activity enter exit animation
Timed disappearance pop-up
学习笔记5--高精地图解决方案