当前位置:网站首页>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
边栏推荐
- 学习笔记6--卫星定位技术(上)
- Uni app running to wechat development tool cannot Preview
- > Could not create task ‘:app:MyTest.main()‘. > SourceSet with name ‘main‘ not found.问题修复
- Kotlin compose multiple item scrolling
- Unity particle special effects series - the poison spray preform is ready, and the unitypackage package is directly used - on
- Activity jump encapsulation
- Events and bubbles in the applet of "wechat applet - Basics"
- 横向滚动的RecycleView一屏显示五个半,低于五个平均分布
- A high density 256 channel electrode cap for dry EEG
- 【黑马早报】罗永浩回应调侃东方甄选;董卿丈夫密春雷被执行超7亿;吉利正式收购魅族;华为发布问界M7;豆瓣为周杰伦专辑提前开分道歉...
猜你喜欢

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

Meitu lost 300 million yuan in currency speculation for half a year. Huawei was exposed to expand its enrollment in Russia. Alphago's peers have made another breakthrough in chess. Today, more big new

Universal double button or single button pop-up

自动化规范检查软件如何发展而来?

AtCoder Beginner Contest 258「ABCDEFG」

Cerebral Cortex:有向脑连接识别帕金森病中广泛存在的功能网络异常

Unity粒子特效系列-毒液喷射预制体做好了,unitypackage包直接用 - 上

如何写出高质量的代码?

Fluent generates icon prompt logo widget
![[论文阅读] CKAN: Collaborative Knowledge-aware Atentive Network for Recommender Systems](/img/6c/5b14f47503033bc2c85a259a968d94.png)
[论文阅读] CKAN: Collaborative Knowledge-aware Atentive Network for Recommender Systems
随机推荐
leetcode:1200. 最小绝对差
自动化规范检查软件如何发展而来?
Timed disappearance pop-up
Zblogphp breadcrumb navigation code
[tips] get the x-axis and y-axis values of cdfplot function in MATLAB
学习笔记6--卫星定位技术(上)
IDEA新建sprintboot项目
到底谁才是“良心”国产品牌?
> Could not create task ‘:app:MyTest.main()‘. > SourceSet with name ‘main‘ not found.问题修复
[C language] the use of dynamic memory development "malloc"
StaticLayout的使用详解
微信小程序中,从一个页面跳转到另一个页面后,在返回后发现页面同步滚动了
Applet image height adaptation and setting text line height
@SerializedName注解使用
Shortcut keys for vscode
天龙八部TLBB系列 - 单体技能群伤
@JsonAdapter注解使用
Glide Mastery
Should the dependency given by the official website be Flink SQL connector MySQL CDC, with dependency added
Cut off 20% of Imagenet data volume, and the performance of the model will not decline! Meta Stanford et al. Proposed a new method, using knowledge distillation to slim down the data set