這篇文章主要為大家展示了微信小程序如何實現(xiàn)收貨地址左滑刪除,內容簡而易懂,希望大家可以學習一下,學習完之后肯定會有收獲的,下面讓小編帶大家一起來看看吧。
效果:
思路:
一、用相對定位和絕對定位,列表放在上層,刪除按鈕放在下層(z-index不要為負)。
二、觸摸事件判斷用戶是否左滑,有 bindtouchstart,bindtouchmove,bindtouchend 三個觸摸事件。
1、bindtouchstart 記錄觸摸開始的點。開始點的坐標在 e.touches[0] 中,這是相對于屏幕的,也就是以屏幕左上方為原點。
2、bindtouchmove 記錄觸摸移動時的點。同上。
3、bindtouchmove 記錄觸摸結束的點。結束點的坐標在 e.changedTouches[0] 中。
通過1、2方法,獲取到觸摸開始點、移動距離,就可以讓列表層隨觸摸點左右移動;
通過3方法,獲取最終點,判斷與開始點的距離,如果這個距離小于刪除按鈕的一半,則還原列表層
代碼:
1、wxml
<view wx:for="{{address}}" style='position: relative;'> <!-- 列表層 --> <view class='list' style='{{item.txtStyle}}' bindtouchstart="touchS" bindtouchmove="touchM" bindtouchend="touchE" data-index='{{index}}'> <!-- 收貨信息 --> <view class='info' bindtap='select_addr' data-id="{{item.id}}"> <view> {{item.name}} <span class="phone">{{item.phone}}</span> <span wx:if="{{item.default == 1}}" class='def'>默認</span> </view> <view> {{item.province}} {{item.address}} </view> </view> <!-- 編輯圖標 --> <view class='edit' bindtap='edit' data-id='{{item.id}}' > <image src='/image/edit.png'></image> </view> </view> <!-- 刪除按鈕 --> <view class="delete" data-id="{{item.id}}" data-index='{{index}}' bindtap="delItem" >刪除</view> </view> <view class='add' bindtap='add'>添加地址</view>
新聞標題:微信小程序如何實現(xiàn)收貨地址左滑刪除-創(chuàng)新互聯(lián)
文章URL:http://www.chinadenli.net/article44/dspehe.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供用戶體驗、自適應網(wǎng)站、網(wǎng)站內鏈、網(wǎng)站營銷、外貿網(wǎng)站建設、網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內容