欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

微信小程序?qū)崿F(xiàn)滑動(dòng)刪除

 更新時(shí)間:2022年08月24日 16:10:20   作者:小Zzzzzzz菇?jīng)? 
這篇文章主要為大家詳細(xì)介紹了微信小程序?qū)崿F(xiàn)滑動(dòng)刪除,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(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)文章

最新評(píng)論