返回
快速导航关闭
当前搜索
网站分类
栏目推荐
实用工具
热门标签
子分类:
创奇学院 >微信 >小程序 >微信小程序 » 正文

微信小程序可以删除掉吗,微信小程序购物车滑动删除

微信小程序 更新时间: 发布时间: 微信小程序归档 最新发布 网站地图



wxml:

<view class="page">

<movable-area class="item-touch" wx:for="{{cartdata}}" wx:index="idx" wx:key="index">

<movable-view bindtouchstart="_touchStart" bindtouchmove="_touchMove" bindtouchend="_touchEnd" x="{{item.x}}" direction="horizontal" inertia="true" out-of-bounds="true" data-i="{{index}}" class="item-touch-list flex" data-id="touch">

{{index}}购物车商品{{item.id}}

</movable-view>

<view class="item-touch-tool">删除</view>

</movable-area>

</view>


wxss:

.page {

position: fixed;

display: flex;

flex-direction: column;

background-color: #f5f5f5;

width: 100%;

height: 100%;

border-top: 20rpx solid#f5f5f5

}

.item-touch {

display: flex;

position: relative;

margin-bottom: 20rpx;

width: calc(750rpx - 148rpx);

height: 100rpx;

line-height: 100rpx;

}

.item-touch-list {

z-index: 10;

width: 750rpx;

height: 100%;

padding-left: 30rpx;

box-sizing: border-box;

background-color: #fff;

}

.item-touch-tool {

width: 148rpx;

position: absolute;

top: 0;

bottom: 0;

left: 100%;

background-color: #f43838;

font-size: 28rpx;

line-height: 100rpx;

text-align: center;

color: #fff;

}


js:

//logs.js

const util = require('../../utils/util.js')

Page({

data: {

logs: [],

cartdata: [{ id: 1, x: 0 }, { id: 2, x: 0 }, { id: 3, x: 0 }],

startX:0,

isLeft:0,

delBtnw:148

},

_touchStart:function(e){

console.log(e);

//排除多点触摸

if(e.touches.length==1){

this.setData({

startX:e.touches[0].clientX

});

}

console.log('start'+util.formatTime(new Date()));

},

_touchMove:function(e){

},

_touchEnd:function(e){

var that=this;

console.log(e);

var cartIndex=e.currentTarget.dataset.i;

var delw=that.data.delBtnw;

if(e.changedTouches.length==1){

var endX = e.changedTouches[0].clientX-that.data.startX;

// 判断是否向左滑动

if (endX>=0){

that.setData({

isLeft:0

})

}else{

that.setData({

isLeft:1

})

}

console.log(endX);

if(Math.abs(endX)<delw/4)

{

that.xMove(cartIndex,0);

}else{

that.xMove(cartIndex,that.data.delBtnw);

}

}

},

xMove:function(i,x){

console.log(i+','+x);

var that=this;

var tempData=that.data.cartdata;

console.log(that.data.isLeft);

if(that.data.isLeft){

tempData[i].x = tempData[i].x - x;

}else

{

tempData[i].x = tempData[i].x + x;

}

that.setData({

cartdata:tempData

});

console.log('xMove:');

console.log(that.data.cartdata);

},

onLoad: function () {

}

})



转载请注明:文章转载自 http://www.320g.com/
本文地址:http://www.320g.com/wxxcx/33918.html
考高分网交流群

扫一扫加入QQ交流群

和更多志同道合朋友一起交流,分享干货资料!
创奇学院客服

扫一扫加客服微信

有疑问请咨询创奇学院微信号,在线为您解答!
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 Copyright 320g.com Rights Reserved. Powered · 创奇学院

ICP备案号:陇ICP备2020003353号