zoukankan      html  css  js  c++  java
  • 微信小程序左滑删除未操作有复位效果

    1、wxml

    <!--pages/test/test.wxml-->
    <view class="page">
    
    <movable-area class="m_a" wx:for="{{plist}}" wx:key="*this" wx:for-index="id" >
      <movable-view class="data_list" direction="horizontal" inertia="true"  x="{{item.leftx}}" out-of-bounds="true"  bindtouchstart="touchS" bindtouchmove="touchM" bindtouchend="touchE" data-index="{{id}}" >
    
       <view  class="d_box">
        <view class="data">{{item.title}}</view>
        <view>删除</view>
       </view>
      </movable-view>
    </movable-area>
    
    </view>

    2.wxss

    /* pages/test/test.wxss */
    .page{
      width: 100vw;
      height: 100vh;
    }
    .m_a{
      width: 100%;
      height: 200rpx;
      border: 1rpx solid gray; 
    }
    .data_list{
      height: 200rpx;
      width: 120%;
      border: 1rpx solid red;
    }
    .d_box{
      display: flex;
      justify-content: flex-start;
      justify-items: center;
      height: 100%;
    }
    .data{
      width: 100vw;
      background: red;
    }

    3.js

    // pages/test/test.js
    Page({
    
      /**
       * 页面的初始数据
       */
      data: {
        plist: [{ "title": "内容内容13131", "leftx": 0 }, { "title": "asdasd内容13131", "leftx": 0 }, { "title": "a是sd内容13131", "leftx": 0 }, { "title": "as水电费多个d内容13131", "leftx": 0 }],
        pcontrolWidth: 200,
      },
    
      /**
       * 生命周期函数--监听页面加载
       */
      onLoad: function (options) {
    
      },
    
      /**
       * 生命周期函数--监听页面初次渲染完成
       */
      onReady: function () {
    
      },
    
      /**
       * 生命周期函数--监听页面显示
       */
      onShow: function () {
    
      },
    
      /**
       * 生命周期函数--监听页面卸载
       */
      onUnload: function () {
    
      },
    
    
      /**
         * 触摸开始
         */
      touchS: function (e) {
        let index = e.currentTarget.dataset.index;
        //遍历复位
        this.data.plist.forEach(function (item, key) {
          if (key != index) {
            item.leftx = 0;
          }
    
        });
        //复位后,赋值
        this.setData({
          plist: this.data.plist,
        });
    
        if (e.touches.length == 1) {
          this.setData({
            //设置触摸起始点水平方向位置
            startX: e.touches[0].clientX
          });
        }
    
    
      },
      /**
       * 触摸移动
       */
      touchM: function (e) {
        console.log(e);
        let index = e.currentTarget.dataset.index;
        var endX = e.touches[0].clientX;
        var disX = this.data.startX - endX;
        var pcontrolWidth = this.data.pcontrolWidth;
        var left = 0;
        if (disX <= 0) {
          left = 0;
        } else if (disX > 0) {
          left = disX;
          if (disX >= pcontrolWidth) {
            //控制手指移动距离最大值为删除按钮的宽度
            left = pcontrolWidth;
          }
        }
    
        this.data.plist[index].leftx = -left;
        this.setData({
          plist: this.data.plist,
        });
        console.log(this.data.plist);
    
      },
      /**
       * 触摸结束
       */
      touchE: function (e) {
    
      }
    
    
    })
  • 相关阅读:
    在UNITY中按钮的高亮用POINT灯实现,效果别具一番风味
    打包场景出错
    探讨 .NET 4 新增的 SortedSet 类
    error CS1010 CS8025 CS1012 CS1525 常见文档错误解决
    安卓机在按HOME键时,UNITY触发的APPLICATION_PAUSE事件
    有几个Pass,对象就会绘制几次
    华东师范大学2017年高等代数考研试题
    华东师范大学2017年数学分析考研试题
    无穷级数的收敛性
    南开大学2017年数学分析高等代数考研试题
  • 原文地址:https://www.cnblogs.com/fps2tao/p/11390024.html
Copyright © 2011-2022 走看看