当前位置:网站首页>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
边栏推荐
- Today in history: the first e-book came out; The inventor of magnetic stripe card was born; The pioneer of handheld computer was born
- Advanced opencv:bgr pixel intensity map
- LiveData 面试题库、解答---LiveData 面试 7 连问~
- uniapp + uniCloud+unipay 实现微信小程序支付功能
- 《剑来》语句摘录(七)
- Energy momentum: how to achieve carbon neutralization in the power industry?
- 驱动制造业产业升级新思路的领域知识网络,什么来头?
- 【黑马早报】罗永浩回应调侃东方甄选;董卿丈夫密春雷被执行超7亿;吉利正式收购魅族;华为发布问界M7;豆瓣为周杰伦专辑提前开分道歉...
- Swift uses userdefaults and codable to save an array of class objects or structure instances
- @Serializedname annotation use
猜你喜欢

Hard core, have you ever seen robots play "escape from the secret room"? (code attached)

WorkManager学习一

Constraintlayout officially provides rounded imagefilterview

Unity particle special effects series - the poison spray preform is ready, and the unitypackage package can be used directly - next

Constrained layout flow

A high density 256 channel electrode cap for dry EEG

双容水箱液位模糊PID控制系统设计与仿真(Matlab/Simulink)

Fluent generates icon prompt logo widget

Usage differences between isempty and isblank

WorkManager的学习二
随机推荐
Unity particle special effects series - the poison spray preform is ready, and the unitypackage package is directly used - on
Window下线程与线程同步总结
Cerebral Cortex:有向脑连接识别帕金森病中广泛存在的功能网络异常
Unity粒子特效系列-毒液喷射预制体做好了,unitypackage包直接用 - 上
Idea create a new sprintboot project
Glide Mastery
Events and bubbles in the applet of "wechat applet - Basics"
驱动制造业产业升级新思路的领域知识网络,什么来头?
Usage differences between isempty and isblank
到底谁才是“良心”国产品牌?
How to get the STW (pause) time of GC (garbage collector)?
天龙八部TLBB系列 - 关于包裹掉落的物品
AtCoder Beginner Contest 258「ABCDEFG」
Apple 5g chip research and development failure? It's too early to get rid of Qualcomm
Tianlong Babu TLBB series - single skill group injury
WorkManager的学习二
Singleton mode encapsulates activity management class
Implementation of smart home project
能源势动:电力行业的碳中和该如何实现?
Glide advanced level