微信小程序?qū)崿F(xiàn)滑動(dòng)刪除
本文實(shí)例為大家分享了微信小程序?qū)崿F(xiàn)滑動(dòng)刪除的具體代碼,供大家參考,具體內(nèi)容如下
wxml
<view class="bgwhite bor-bom-f2 row just-btw alignitems? {{item.isTouchMove ? 'touch-move-active' : ''}}" wx:for="{{dataList}}" wx:key="index"> ? <view class="item-left" data-index="{{index}}"? ? bindtouchstart="touchStart" bindtouchmove="touchMove"> ? ? <view class="m-lr-30 row just-btw alignitems"> ? ? ? <view> ? ? ? ? <view class="f28">{{item.name}}</view> ? ? ? ? <view class="row m-t-15"> ? ? ? ? ? <view class="c999">張三</view> ? ? ? ? ? <view class="c999 m-l-50">17637930507</view> ? ? ? ? </view> ? ? ? </view> ? ? ? <image src="../../../images/phone_mid.png" mode="aspectFit"? ? ? ? style="width:43rpx;height:43rpx;"></image> ? ? </view> ? </view> ? <view class="delete">刪除</view> </view>
js
// pages/user/suppliermana/suppliermana.js Page({ ? /** ? ?* 頁(yè)面的初始數(shù)據(jù) ? ?*/ ? data: { ? ? // 設(shè)置開(kāi)始的位置 ? ? startX: 0, ? ? startY: 0, ? ? dataList:[], ? }, ? /** ? ?* 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面加載 ? ?*/ ? onLoad: function (options) { ?? ??? ?for (var i = 0; i < 10; i++) { ? ? ? ? ?this.data.dataList.push({ ? ? ? ? ? ? ?content: "供應(yīng)商名稱" + i, ? ? ? ? ? ? ?isTouchMove: false //默認(rèn)全隱藏刪除 ? ? ? ? ?}) ? ? ?} ? ? ?this.setData({ ? ? ? ? ?dataList: this.data.dataList ? ? ?}) ? }, ? // 開(kāi)始滑動(dòng) ? touchStart(e) { ? ? console.log('touchStart=====>', e); ? ? let dataList = [...this.data.dataList] ? ? dataList.forEach(item => { ? ? ? // 讓原先滑動(dòng)的塊隱藏 ? ? ? if (item.isTouchMove) { ? ? ? ? item.isTouchMove = !item.isTouchMove; ? ? ? } ? ? }); ? ? // 初始化開(kāi)始位置 ? ? this.setData({ ? ? ? dataList: dataList, ? ? ? startX: e.touches[0].clientX, ? ? ? startY: e.touches[0].clientY ? ? }) ? }, ? // 滑動(dòng)~ ? touchMove(e) { ? ? console.log('touchMove=====>', e); ? ? let moveX = e.changedTouches[0].clientX; ? ? let moveY = e.changedTouches[0].clientY; ? ? let indexs = e.currentTarget.dataset.index; ? ? let dataList = [...this.data.dataList] ? ? // 拿到滑動(dòng)的角度,判斷是否大于 30°,若大于,則不滑動(dòng) ? ? let angle = this.angle({ ? ? ? X: this.data.startX, ? ? ? Y: this.data.startY ? ? }, { ? ? ? X: moveX, ? ? ? Y: moveY ? ? }); ? ? dataList.forEach((item, index) => { ? ? ? item.isTouchMove = false; ? ? ? // 如果滑動(dòng)的角度大于30° 則直接return; ? ? ? if (angle > 30) { ? ? ? ? return ? ? ? } ? ?? ? ? // 判斷是否是當(dāng)前滑動(dòng)的塊,然后對(duì)應(yīng)修改 isTouchMove 的值,實(shí)現(xiàn)滑動(dòng)效果 ? ? ? if (indexs === index) { ? ? ? ? if (moveX > this.data.startX) { // 右滑 ? ? ? ? ? item.isTouchMove = false; ? ? ? ? } else { // 左滑 ? ? ? ? ? item.isTouchMove = true; ? ? ? ? } ? ? ? } ? ? }) ? ? this.setData({ ? ? ? dataList ? ? }) ? }, ? /** ? ?* 計(jì)算滑動(dòng)角度 ? ?* @param {Object} start 起點(diǎn)坐標(biāo) ? ?* @param {Object} end 終點(diǎn)坐標(biāo) ? ?*/ ? angle: function (start, end) { ? ? var _X = end.X - start.X, ? ? ? _Y = end.Y - start.Y ? ? //返回角度 /Math.atan()返回?cái)?shù)字的反正切值 ? ? return 360 * Math.atan(_Y / _X) / (2 * Math.PI); ? }, ? /** ? ?* 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面初次渲染完成 ? ?*/ ? onReady: function () { ? }, ? /** ? ?* 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面顯示 ? ?*/ ? onShow: function () { ? }, ? /** ? ?* 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面隱藏 ? ?*/ ? onHide: function () { ? }, ? /** ? ?* 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面卸載 ? ?*/ ? onUnload: function () { ? }, ? /** ? ?* 頁(yè)面相關(guān)事件處理函數(shù)--監(jiān)聽(tīng)用戶下拉動(dòng)作 ? ?*/ ? onPullDownRefresh: function () { ? }, ? /** ? ?* 頁(yè)面上拉觸底事件的處理函數(shù) ? ?*/ ? onReachBottom: function () { ? }, ? /** ? ?* 用戶點(diǎn)擊右上角分享 ? ?*/ ? onShareAppMessage: function () { ? } })
wxss
.item-left { ? width: 100%; ? margin-left: -140rpx; ? transform: translateX(140rpx); ? -webkit-transition: all 0.4s; ? transition: all 0.4s; ? -webkit-transform: translateX(140rpx); } .delete { ? height: 100%; ? width: 140rpx; ? background: #FF4128; ? color:#fff; ? text-align: center; ? padding:50rpx 0; ? transform: translateX(150rpx); ? -webkit-transition: all 0.4s; ? transition: all 0.4s; ? -webkit-transform: translateX(150rpx); } .touch-move-active .item-left, .touch-move-active .delete { ? -webkit-transform: translateX(0); ? transform: translateX(0); }
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
js倒計(jì)時(shí)小實(shí)例(多次定時(shí))
這篇文章主要介紹了js實(shí)現(xiàn)可多次定時(shí)的倒計(jì)時(shí)小實(shí)例,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-12-12原生Js與jquery的多組處理, 僅展開(kāi)一個(gè)區(qū)塊的折疊效果
同一個(gè)頁(yè)面, 有多組(不固定), 每組區(qū)塊數(shù)量不一定一樣的小區(qū)塊. 要求每次只展開(kāi)一個(gè)區(qū)塊,需要的朋友可以參考下。2011-01-01js動(dòng)態(tài)生成按鈕并動(dòng)態(tài)生成8位隨機(jī)數(shù)
用js生成按鈕,動(dòng)態(tài)生成8位隨機(jī)數(shù)的腳本2008-09-09javascript下string.format函數(shù)補(bǔ)充
在上一篇中,自謙懶人的咚鏘留言指出樓豬改寫(xiě)的format函數(shù)在參數(shù)輸入11個(gè)后不起作用了2010-08-08基于JS實(shí)現(xiàn)動(dòng)態(tài)跟隨特效的示例代碼
這篇文章主要介紹了如何利用JavaScript實(shí)現(xiàn)動(dòng)態(tài)跟隨特效,文中的示例代碼講解詳細(xì),對(duì)我們學(xué)習(xí)JS有一定的幫助,感興趣的小伙伴可以了解一下2022-06-06location.hash保存頁(yè)面狀態(tài)的技巧
hash 屬性是一個(gè)可讀可寫(xiě)的字符串,該字符串是 URL 的錨部分(從 # 號(hào)開(kāi)始的部分)。接下來(lái)通過(guò)本文給大家介紹location.hash保存頁(yè)面狀態(tài)的相關(guān)內(nèi)容,感興趣的朋友一起學(xué)習(xí)吧2016-04-04javascript+html5+css3自定義彈出窗口效果
這篇文章主要為大家詳細(xì)介紹了javascript+html5+css3自定義彈出窗口效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-10-10