国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 熱點 > 微信 > 正文

微信小程序實現收貨地址左滑刪除

2024-07-22 01:17:54
字體:
來源:轉載
供稿:網友

本文實例為大家分享了微信小程序實現收貨地址左滑刪除的具體代碼,供大家參考,具體內容如下

效果:

思路:

一、用相對定位和絕對定位,列表放在上層,刪除按鈕放在下層(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>

2、wxss

page{ background-color: #F0EFF5;}.list{ position: relative; z-index: 2; overflow: hidden; background-color: white; margin-top: 2rpx; padding: 25rpx; display: flex; align-items: center; justify-content:space-between; min-height: 150rpx;}.delete{ position: absolute; top:0rpx; background-color: #e64340; width: 180rpx; text-align: center; z-index: 1; right: 0; color: #fff; height: 100%; display: flex; align-items: center; justify-content: center;}.info{ display: flex; flex-direction: column; align-items: flex-start;}.info view:first-child{ text-align: center; font-size: 35rpx; margin-bottom: 10rpx;}.info view:nth-child(2){ font-size: 30rpx; margin-bottom: 10rpx;}.def{ font-size: 30rpx; border:1rpx solid red; border-radius: 5rpx; padding:0 10rpx; color: red; margin-right: 10rpx;}.phone{ color:gray;font-size:30rpx;margin: 0 20rpx;}.edit{ padding:40rpx;}.edit image{ width: 40rpx; height: 40rpx; margin-left:10rpx;}.add{ width: 650rpx; border: 2rpx solid gray; height: 100rpx; line-height: 100rpx; text-align: center; font-size: 30rpx; border-radius: 10rpx; position: fixed; bottom: 50rpx; left: 50rpx; background-color: white;}            
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 津南区| 蓝田县| 聂荣县| 东莞市| 蓬溪县| 土默特左旗| 绥芬河市| 平乐县| 武乡县| 石阡县| 康马县| 文安县| 游戏| 鄂温| 京山县| 永春县| 萨迦县| 昌邑市| 桃江县| 财经| 龙岩市| 吴川市| 鲜城| 德惠市| 沾化县| 纳雍县| 柳江县| 沂南县| 巴林右旗| 老河口市| 华蓥市| 牟定县| 宜城市| 贵州省| 永福县| 温宿县| 阿合奇县| 阿克| 安宁市| 西乌| 黎平县|