微信小程序?qū)崿F(xiàn)左滑刪除效果
更新時間:2020年11月18日 11:21:11 作者:Archer_yy
這篇文章主要為大家詳細介紹了微信小程序?qū)崿F(xiàn)左滑刪除效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
微信小程序?qū)崿F(xiàn)左滑刪除效果的具體代碼,供大家參考,具體內(nèi)容如下

.wxml
<scroll-view scroll-y="{{isScroll}}" style='width:{{windowWidth}}px;height:{{windowHeight}}px'>
<block wx:key="item" wx:for="{{data}}">
<view data-index='{{index}}' class="custom_item" bindtouchstart="drawStart" bindtouchmove="drawMove" bindtouchend="drawEnd" style="right:{{item.right}}rpx">
<view class="content">{{item.content}}</view>
<view class="remove" bindtap="delItem">刪除 </view>
</view>
</block>
</scroll-view>
.js
Page({
data: {
delBtnWidth: 160,
data: [{ content: "采購", right: 0 }, { content: "供應(yīng)", right: 0 }, { content: "采購", right: 0 }, { content: "供應(yīng)", right: 0}],
isScroll: true,
windowWidth:0,
windowHeight: 0,
},
onLoad: function (options) {
var that = this;
wx.getSystemInfo({
success: function (res) {
that.setData({
windowWidth: res.windowWidth,
windowHeight: res.windowHeight
});
}
});
},
drawStart: function (e) {
// console.log("drawStart");
var touch = e.touches[0]
for (var index in this.data.data) {
var item = this.data.data[index]
item.right = 0
}
this.setData({
data: this.data.data,
startX: touch.clientX,
})
},
drawMove: function (e) {
var touch = e.touches[0]
var item = this.data.data[e.currentTarget.dataset.index]
var disX = this.data.startX - touch.clientX
if (disX >= 20) {
if (disX > this.data.delBtnWidth) {
disX = this.data.delBtnWidth
}
item.right = disX
this.setData({
isScroll: false,
data: this.data.data
})
} else {
item.right = 0
this.setData({
isScroll: true,
data: this.data.data
})
}
},
drawEnd: function (e) {
var item = this.data.data[e.currentTarget.dataset.index]
if (item.right >= this.data.delBtnWidth / 2) {
item.right = this.data.delBtnWidth
this.setData({
isScroll: true,
data: this.data.data,
})
} else {
item.right = 0
this.setData({
isScroll: true,
data: this.data.data,
})
}
},
delItem: function (e) {
}
})
.wxss
.custom_item{
height: 240rpx;
width: 100%;
display: flex;
position: relative;
}
.remove{
width: 160rpx;
height: 100%;
background-color: red;
color: white;
position: absolute;
top: 0;
right: -160rpx;
display: flex;
justify-content: center;
align-items: center;
}
為大家推薦現(xiàn)在關(guān)注度比較高的微信小程序教程一篇:《微信小程序開發(fā)教程》小編為大家精心整理的,希望喜歡。
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
微信小程序 動態(tài)綁定數(shù)據(jù)及動態(tài)事件處理
這篇文章主要介紹了微信小程序 動態(tài)綁定數(shù)據(jù)及動態(tài)事件處理的相關(guān)資料,需要的朋友可以參考下2017-03-03
[js高手之路]設(shè)計模式系列課程-發(fā)布者,訂閱者重構(gòu)購物車的實例
下面小編就為大家?guī)硪黄猍js高手之路]設(shè)計模式系列課程-發(fā)布者,訂閱者重構(gòu)購物車的實例。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-08-08
JavaScript使用Broadcast?Channel實現(xiàn)前端跨標簽頁通信
這篇文章主要為大家詳細介紹了JavaScript如何使用Broadcast?Channel實現(xiàn)前端跨標簽頁通信,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2024-04-04

