小程序——左滑删除

官方文档
https://developers.weixin.qq.com/miniprogram/dev/component/movable-area.html
左滑删除功能
movable-area
movable-view
当movable-view小于movable-area时,只能在movable-area内部移动
当movable-view大于movable-area时,移动范围必须包含movable-area(X,Y方向分开考虑)
direction:移动方向,有all、vertical、horizontal、none
x:定义x轴方向的偏移
wxml:

<view class="cell">
  <movable-area class="cell_movearea">
    <movable-view class="cell_moveview" 
    direction="horizontal" 
    x="{{isOpen?'-150rpx':'0'}}"
    bindtouchstart="_moveTouchStart"
    bindtouchend="_moveTouchEnd">
      zheshiyhige cell
    </movable-view>
  </movable-area>
  <button type="warn" class="cell_btn">删除</button>
</view>

wxss

.cell{
height: 100rpx;
width: 750rpx;
display: flex;
}
.cell .cell_movearea{
height: 100rpx;
flex: 1;
background-color: tomato;
}
.cell .cell_movearea .cell_moveview{
height: 100rpx;
width: 750rpx;
background-color: cyan;
z-index: 99;
}
.cell .cell_btn{
height: 100rpx;
width: 150rpx;
line-height: 100rpx;
border-radius: 0px;
}

js

let touchStart=0;
Page({
  _moveTouchStart:function(evt){
    // console.log(evt);
    touchStart = evt.changedTouches[0].pageX;
  },
  _moveTouchEnd:function(evt){
    // console.log(evt);
    let touchEnd = evt.changedTouches[0].pageX;
    let cha = touchEnd - touchStart;
    if(cha<-40){
      this.setData({
        isOpen:true
      })
    }else if(cha>40){
      this.setData({
        isOpen: false
      })
    }else{
      this.setData({
        isOpen: this.data.isOpen
      })
    }
  },

  /**
   * 页面的初始数据
   */
  data: {
    isOpen:false
  },
}

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值