说啥好啊 發表於 2019-8-29 15:50:00

微信小程序实现左滑删除效果(原生/uni-app)

<h3>实现效果</h3>
<ol>
<li>列表中侧滑删除</li>
<li>删除不同时存在</li>
<li>scrollview上下滑动与侧滑删除不影响</li>
</ol>
<p><img src="https://img2018.cnblogs.com/blog/1307134/201908/1307134-20190829154520146-509629429.png" alt="" width="203" height="318"></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<h3>uni-app实现</h3>
<p>html部分</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 255, 1)">&lt;</span><span style="color: rgba(128, 0, 0, 1)">template</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span>
    <span style="color: rgba(0, 0, 255, 1)">&lt;</span><span style="color: rgba(128, 0, 0, 1)">scroll-view </span><span style="color: rgba(255, 0, 0, 1)">:scroll-y</span><span style="color: rgba(0, 0, 255, 1)">="isScroll"</span><span style="color: rgba(255, 0, 0, 1)"> :style</span><span style="color: rgba(0, 0, 255, 1)">="{ height: windowHeight + 'px' }"</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span>
      <span style="color: rgba(0, 0, 255, 1)">&lt;</span><span style="color: rgba(128, 0, 0, 1)">block </span><span style="color: rgba(255, 0, 0, 1)">:key</span><span style="color: rgba(0, 0, 255, 1)">="index"</span><span style="color: rgba(255, 0, 0, 1)"> v-for</span><span style="color: rgba(0, 0, 255, 1)">="(item, index) in dataList"</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span>
            <span style="color: rgba(0, 0, 255, 1)">&lt;</span><span style="color: rgba(128, 0, 0, 1)">view </span><span style="color: rgba(255, 0, 0, 1)">:data-index</span><span style="color: rgba(0, 0, 255, 1)">="index"</span><span style="color: rgba(255, 0, 0, 1)"> class</span><span style="color: rgba(0, 0, 255, 1)">="order-item"</span><span style="color: rgba(255, 0, 0, 1)"> @touchstart</span><span style="color: rgba(0, 0, 255, 1)">="drawStart"</span><span style="color: rgba(255, 0, 0, 1)"> @touchmove</span><span style="color: rgba(0, 0, 255, 1)">="drawMove"</span><span style="color: rgba(255, 0, 0, 1)"> @touchend</span><span style="color: rgba(0, 0, 255, 1)">="drawEnd"</span><span style="color: rgba(255, 0, 0, 1)"> :style</span><span style="color: rgba(0, 0, 255, 1)">="{ right: item.right + 'rpx' }"</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span>
                <span style="color: rgba(0, 0, 255, 1)">&lt;</span><span style="color: rgba(128, 0, 0, 1)">view </span><span style="color: rgba(255, 0, 0, 1)">class</span><span style="color: rgba(0, 0, 255, 1)">="content"</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span>{{ item.content }}<span style="color: rgba(0, 0, 255, 1)">&lt;/</span><span style="color: rgba(128, 0, 0, 1)">view</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span>
                <span style="color: rgba(0, 0, 255, 1)">&lt;</span><span style="color: rgba(128, 0, 0, 1)">view </span><span style="color: rgba(255, 0, 0, 1)">class</span><span style="color: rgba(0, 0, 255, 1)">="remove"</span><span style="color: rgba(255, 0, 0, 1)"> @click</span><span style="color: rgba(0, 0, 255, 1)">="delItem"</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span>删除<span style="color: rgba(0, 0, 255, 1)">&lt;/</span><span style="color: rgba(128, 0, 0, 1)">view</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span>
            <span style="color: rgba(0, 0, 255, 1)">&lt;/</span><span style="color: rgba(128, 0, 0, 1)">view</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span>
      <span style="color: rgba(0, 0, 255, 1)">&lt;/</span><span style="color: rgba(128, 0, 0, 1)">block</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span>
    <span style="color: rgba(0, 0, 255, 1)">&lt;/</span><span style="color: rgba(128, 0, 0, 1)">scroll-view</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span>
<span style="color: rgba(0, 0, 255, 1)">&lt;/</span><span style="color: rgba(128, 0, 0, 1)">template</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span></pre>
</div>
<p>&nbsp;</p>
<p>js部分</p>
<div class="cnblogs_code">
<pre>&lt;script&gt;<span style="color: rgba(0, 0, 0, 1)">
export </span><span style="color: rgba(0, 0, 255, 1)">default</span><span style="color: rgba(0, 0, 0, 1)"> {
    data() {
      </span><span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)"> {
            delBtnWidth: </span>160<span style="color: rgba(0, 0, 0, 1)">,
            dataList: [
                { content: </span>'1', right: 0<span style="color: rgba(0, 0, 0, 1)"> },
                { content: </span>'2', right: 0<span style="color: rgba(0, 0, 0, 1)"> },
                { content: </span>'3', right: 0<span style="color: rgba(0, 0, 0, 1)"> },
                { content: </span>'4', right: 0<span style="color: rgba(0, 0, 0, 1)"> },
                { content: </span>'5', right: 0<span style="color: rgba(0, 0, 0, 1)"> },
                { content: </span>'6', right: 0<span style="color: rgba(0, 0, 0, 1)"> },
                { content: </span>'7', right: 0<span style="color: rgba(0, 0, 0, 1)"> },
                { content: </span>'8', right: 0<span style="color: rgba(0, 0, 0, 1)"> },
                { content: </span>'9', right: 0<span style="color: rgba(0, 0, 0, 1)"> },
                { content: </span>'10', right: 0<span style="color: rgba(0, 0, 0, 1)"> }
            ],
            isScroll: </span><span style="color: rgba(0, 0, 255, 1)">true</span><span style="color: rgba(0, 0, 0, 1)">,
            windowHeight: </span>0<span style="color: rgba(0, 0, 0, 1)">
      };
    },
    onLoad: </span><span style="color: rgba(0, 0, 255, 1)">function</span><span style="color: rgba(0, 0, 0, 1)">(options) {
      </span><span style="color: rgba(0, 0, 255, 1)">var</span> that = <span style="color: rgba(0, 0, 255, 1)">this</span><span style="color: rgba(0, 0, 0, 1)">;
      wx.getSystemInfo({
            success: </span><span style="color: rgba(0, 0, 255, 1)">function</span><span style="color: rgba(0, 0, 0, 1)">(res) {
                that.windowHeight </span>=<span style="color: rgba(0, 0, 0, 1)"> res.windowHeight;
            }
      });
    },
    methods: {
      drawStart: </span><span style="color: rgba(0, 0, 255, 1)">function</span><span style="color: rgba(0, 0, 0, 1)">(e) {
            </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> console.log("drawStart");</span>
            <span style="color: rgba(0, 0, 255, 1)">var</span> touch = e.touches;
            </span><span style="color: rgba(0, 0, 255, 1)">for</span> (<span style="color: rgba(0, 0, 255, 1)">var</span> index <span style="color: rgba(0, 0, 255, 1)">in</span> <span style="color: rgba(0, 0, 255, 1)">this</span><span style="color: rgba(0, 0, 0, 1)">.dataList) {
                </span><span style="color: rgba(0, 0, 255, 1)">this</span>.dataList.right = 0<span style="color: rgba(0, 0, 0, 1)">;
            }
            </span><span style="color: rgba(0, 0, 255, 1)">this</span>.startX =<span style="color: rgba(0, 0, 0, 1)"> touch.clientX;
      },
      drawMove: </span><span style="color: rgba(0, 0, 255, 1)">function</span><span style="color: rgba(0, 0, 0, 1)">(e) {
            </span><span style="color: rgba(0, 0, 255, 1)">var</span> touch = e.touches;
            </span><span style="color: rgba(0, 0, 255, 1)">var</span> item = <span style="color: rgba(0, 0, 255, 1)">this</span><span style="color: rgba(0, 0, 0, 1)">.dataList;
            </span><span style="color: rgba(0, 0, 255, 1)">var</span> disX = <span style="color: rgba(0, 0, 255, 1)">this</span>.startX -<span style="color: rgba(0, 0, 0, 1)"> touch.clientX;

            </span><span style="color: rgba(0, 0, 255, 1)">if</span> (disX &gt;= 20<span style="color: rgba(0, 0, 0, 1)">) {
                </span><span style="color: rgba(0, 0, 255, 1)">if</span> (disX &gt; <span style="color: rgba(0, 0, 255, 1)">this</span><span style="color: rgba(0, 0, 0, 1)">.delBtnWidth) {
                  disX </span>= <span style="color: rgba(0, 0, 255, 1)">this</span><span style="color: rgba(0, 0, 0, 1)">.delBtnWidth;
                }
                </span><span style="color: rgba(0, 0, 255, 1)">this</span>.isScroll = <span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)">;
                </span><span style="color: rgba(0, 0, 255, 1)">this</span>.dataList.right =<span style="color: rgba(0, 0, 0, 1)"> disX;
            } </span><span style="color: rgba(0, 0, 255, 1)">else</span><span style="color: rgba(0, 0, 0, 1)"> {
                </span><span style="color: rgba(0, 0, 255, 1)">this</span>.isScroll = <span style="color: rgba(0, 0, 255, 1)">true</span><span style="color: rgba(0, 0, 0, 1)">;
                </span><span style="color: rgba(0, 0, 255, 1)">this</span>.dataList.right = 0<span style="color: rgba(0, 0, 0, 1)">;
            }
      },
      drawEnd: </span><span style="color: rgba(0, 0, 255, 1)">function</span><span style="color: rgba(0, 0, 0, 1)">(e) {
            </span><span style="color: rgba(0, 0, 255, 1)">var</span> item = <span style="color: rgba(0, 0, 255, 1)">this</span><span style="color: rgba(0, 0, 0, 1)">.dataList;
            </span><span style="color: rgba(0, 0, 255, 1)">if</span> (item.right &gt;= <span style="color: rgba(0, 0, 255, 1)">this</span>.delBtnWidth / 2<span style="color: rgba(0, 0, 0, 1)">) {
                </span><span style="color: rgba(0, 0, 255, 1)">this</span>.isScroll = <span style="color: rgba(0, 0, 255, 1)">true</span><span style="color: rgba(0, 0, 0, 1)">;
                </span><span style="color: rgba(0, 0, 255, 1)">this</span>.dataList.right = <span style="color: rgba(0, 0, 255, 1)">this</span><span style="color: rgba(0, 0, 0, 1)">.delBtnWidth;
            } </span><span style="color: rgba(0, 0, 255, 1)">else</span><span style="color: rgba(0, 0, 0, 1)"> {
                </span><span style="color: rgba(0, 0, 255, 1)">this</span>.isScroll = <span style="color: rgba(0, 0, 255, 1)">true</span><span style="color: rgba(0, 0, 0, 1)">;
                </span><span style="color: rgba(0, 0, 255, 1)">this</span>.dataList.right = 0<span style="color: rgba(0, 0, 0, 1)">;
            }
      },
      delItem() {
            console.log(</span>'删除'<span style="color: rgba(0, 0, 0, 1)">);
      }
    }
};
</span>&lt;/script&gt;</pre>
</div>
<p>&nbsp;</p>
<p>css样式</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(128, 0, 0, 1)">&lt;style scoped&gt;
.order-item </span>{<span style="color: rgba(255, 0, 0, 1)">
    height</span>:<span style="color: rgba(0, 0, 255, 1)"> 240rpx</span>;<span style="color: rgba(255, 0, 0, 1)">
    width</span>:<span style="color: rgba(0, 0, 255, 1)"> 100%</span>;<span style="color: rgba(255, 0, 0, 1)">
    display</span>:<span style="color: rgba(0, 0, 255, 1)"> flex</span>;<span style="color: rgba(255, 0, 0, 1)">
    position</span>:<span style="color: rgba(0, 0, 255, 1)"> relative</span>;
}<span style="color: rgba(128, 0, 0, 1)">

.remove </span>{<span style="color: rgba(255, 0, 0, 1)">
    width</span>:<span style="color: rgba(0, 0, 255, 1)"> 160rpx</span>;<span style="color: rgba(255, 0, 0, 1)">
    height</span>:<span style="color: rgba(0, 0, 255, 1)"> 100%</span>;<span style="color: rgba(255, 0, 0, 1)">
    background-color</span>:<span style="color: rgba(0, 0, 255, 1)"> red</span>;<span style="color: rgba(255, 0, 0, 1)">
    color</span>:<span style="color: rgba(0, 0, 255, 1)"> white</span>;<span style="color: rgba(255, 0, 0, 1)">
    position</span>:<span style="color: rgba(0, 0, 255, 1)"> absolute</span>;<span style="color: rgba(255, 0, 0, 1)">
    top</span>:<span style="color: rgba(0, 0, 255, 1)"> 0</span>;<span style="color: rgba(255, 0, 0, 1)">
    right</span>:<span style="color: rgba(0, 0, 255, 1)"> -160rpx</span>;<span style="color: rgba(255, 0, 0, 1)">
    display</span>:<span style="color: rgba(0, 0, 255, 1)"> flex</span>;<span style="color: rgba(255, 0, 0, 1)">
    justify-content</span>:<span style="color: rgba(0, 0, 255, 1)"> center</span>;<span style="color: rgba(255, 0, 0, 1)">
    align-items</span>:<span style="color: rgba(0, 0, 255, 1)"> center</span>;
}<span style="color: rgba(128, 0, 0, 1)">
&lt;/style&gt;</span></pre>
</div>
<p>&nbsp;</p>
<p>&nbsp;</p>
<h3>小程序原生开发</h3>
<p>html部分</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 255, 1)">&lt;</span><span style="color: rgba(128, 0, 0, 1)">scroll-view </span><span style="color: rgba(255, 0, 0, 1)">scroll-y</span><span style="color: rgba(0, 0, 255, 1)">="{{isScroll}}"</span><span style="color: rgba(255, 0, 0, 1)"> style</span><span style="color: rgba(0, 0, 255, 1)">='height:{{windowHeight}}px'</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span>
    <span style="color: rgba(0, 0, 255, 1)">&lt;</span><span style="color: rgba(128, 0, 0, 1)">block </span><span style="color: rgba(255, 0, 0, 1)">wx:key</span><span style="color: rgba(0, 0, 255, 1)">="item"</span><span style="color: rgba(255, 0, 0, 1)"> wx:for</span><span style="color: rgba(0, 0, 255, 1)">="{{data}}"</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span>
    <span style="color: rgba(0, 0, 255, 1)">&lt;</span><span style="color: rgba(128, 0, 0, 1)">view </span><span style="color: rgba(255, 0, 0, 1)">data-index</span><span style="color: rgba(0, 0, 255, 1)">='{{index}}' </span><span style="color: rgba(255, 0, 0, 1)">class</span><span style="color: rgba(0, 0, 255, 1)">="order-item"</span><span style="color: rgba(255, 0, 0, 1)"> bindtouchstart</span><span style="color: rgba(0, 0, 255, 1)">="drawStart"</span><span style="color: rgba(255, 0, 0, 1)"> bindtouchmove</span><span style="color: rgba(0, 0, 255, 1)">="drawMove"</span><span style="color: rgba(255, 0, 0, 1)"> bindtouchend</span><span style="color: rgba(0, 0, 255, 1)">="drawEnd"</span><span style="color: rgba(255, 0, 0, 1)"> style</span><span style="color: rgba(0, 0, 255, 1)">="right:{{item.right}}rpx"</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span>
      <span style="color: rgba(0, 0, 255, 1)">&lt;</span><span style="color: rgba(128, 0, 0, 1)">view </span><span style="color: rgba(255, 0, 0, 1)">class</span><span style="color: rgba(0, 0, 255, 1)">="content"</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span>{{item.content}}<span style="color: rgba(0, 0, 255, 1)">&lt;/</span><span style="color: rgba(128, 0, 0, 1)">view</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span>
      <span style="color: rgba(0, 0, 255, 1)">&lt;</span><span style="color: rgba(128, 0, 0, 1)">view </span><span style="color: rgba(255, 0, 0, 1)">class</span><span style="color: rgba(0, 0, 255, 1)">="remove"</span><span style="color: rgba(255, 0, 0, 1)"> bindtap</span><span style="color: rgba(0, 0, 255, 1)">="delItem"</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span>删除 <span style="color: rgba(0, 0, 255, 1)">&lt;/</span><span style="color: rgba(128, 0, 0, 1)">view</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span>
    <span style="color: rgba(0, 0, 255, 1)">&lt;/</span><span style="color: rgba(128, 0, 0, 1)">view</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span>
    <span style="color: rgba(0, 0, 255, 1)">&lt;/</span><span style="color: rgba(128, 0, 0, 1)">block</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span>
<span style="color: rgba(0, 0, 255, 1)">&lt;/</span><span style="color: rgba(128, 0, 0, 1)">scroll-view</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span></pre>
</div>
<p>&nbsp;</p>
<p>js部分</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 0, 1)">Page({
data: {
    delBtnWidth:</span>160<span style="color: rgba(0, 0, 0, 1)">,
    data: [{ content: </span>"1", right: 0 }, { content: "2", right: 0 }, { content: "3", right: 0 }, { content: "4", right: 0 }, { content: "5", right: 0 }, { content: "6", right: 0 }, { content: "7", right: 0 }, { content: "8", right: 0 }, { content: "9", right: 0 }, { content: "10",right: 0<span style="color: rgba(0, 0, 0, 1)"> }],
    isScroll:</span><span style="color: rgba(0, 0, 255, 1)">true</span><span style="color: rgba(0, 0, 0, 1)">,
    windowHeight:</span>0<span style="color: rgba(0, 0, 0, 1)">,
},
onLoad: </span><span style="color: rgba(0, 0, 255, 1)">function</span><span style="color: rgba(0, 0, 0, 1)"> (options) {
    </span><span style="color: rgba(0, 0, 255, 1)">var</span> that = <span style="color: rgba(0, 0, 255, 1)">this</span><span style="color: rgba(0, 0, 0, 1)">;
    wx.getSystemInfo({
      success: </span><span style="color: rgba(0, 0, 255, 1)">function</span><span style="color: rgba(0, 0, 0, 1)"> (res) {
      that.setData({
          windowHeight: res.windowHeight
      });
      }
    });
},
drawStart: </span><span style="color: rgba(0, 0, 255, 1)">function</span><span style="color: rgba(0, 0, 0, 1)"> (e) {
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> console.log("drawStart");</span>
    <span style="color: rgba(0, 0, 255, 1)">var</span> touch = e.touches

    </span><span style="color: rgba(0, 0, 255, 1)">for</span>(<span style="color: rgba(0, 0, 255, 1)">var</span> index <span style="color: rgba(0, 0, 255, 1)">in</span> <span style="color: rgba(0, 0, 255, 1)">this</span><span style="color: rgba(0, 0, 0, 1)">.data.data) {
      </span><span style="color: rgba(0, 0, 255, 1)">var</span> item = <span style="color: rgba(0, 0, 255, 1)">this</span><span style="color: rgba(0, 0, 0, 1)">.data.data
      item.right </span>= 0<span style="color: rgba(0, 0, 0, 1)">
    }
    </span><span style="color: rgba(0, 0, 255, 1)">this</span><span style="color: rgba(0, 0, 0, 1)">.setData({
      data: </span><span style="color: rgba(0, 0, 255, 1)">this</span><span style="color: rgba(0, 0, 0, 1)">.data.data,
      startX: touch.clientX,
    })

},
drawMove: </span><span style="color: rgba(0, 0, 255, 1)">function</span><span style="color: rgba(0, 0, 0, 1)"> (e) {
    </span><span style="color: rgba(0, 0, 255, 1)">var</span> touch = e.touches
    </span><span style="color: rgba(0, 0, 255, 1)">var</span> item = <span style="color: rgba(0, 0, 255, 1)">this</span><span style="color: rgba(0, 0, 0, 1)">.data.data
    </span><span style="color: rgba(0, 0, 255, 1)">var</span> disX = <span style="color: rgba(0, 0, 255, 1)">this</span>.data.startX -<span style="color: rgba(0, 0, 0, 1)"> touch.clientX
   
    </span><span style="color: rgba(0, 0, 255, 1)">if</span> (disX &gt;= 20<span style="color: rgba(0, 0, 0, 1)">) {
      </span><span style="color: rgba(0, 0, 255, 1)">if</span> (disX &gt; <span style="color: rgba(0, 0, 255, 1)">this</span><span style="color: rgba(0, 0, 0, 1)">.data.delBtnWidth) {
      disX </span>= <span style="color: rgba(0, 0, 255, 1)">this</span><span style="color: rgba(0, 0, 0, 1)">.data.delBtnWidth
      }
      item.right </span>=<span style="color: rgba(0, 0, 0, 1)"> disX
      </span><span style="color: rgba(0, 0, 255, 1)">this</span><span style="color: rgba(0, 0, 0, 1)">.setData({
      isScroll: </span><span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)">,
      data: </span><span style="color: rgba(0, 0, 255, 1)">this</span><span style="color: rgba(0, 0, 0, 1)">.data.data
      })
    } </span><span style="color: rgba(0, 0, 255, 1)">else</span><span style="color: rgba(0, 0, 0, 1)"> {
      item.right </span>= 0
      <span style="color: rgba(0, 0, 255, 1)">this</span><span style="color: rgba(0, 0, 0, 1)">.setData({
      isScroll: </span><span style="color: rgba(0, 0, 255, 1)">true</span><span style="color: rgba(0, 0, 0, 1)">,
      data: </span><span style="color: rgba(0, 0, 255, 1)">this</span><span style="color: rgba(0, 0, 0, 1)">.data.data
      })
    }
},
drawEnd: </span><span style="color: rgba(0, 0, 255, 1)">function</span><span style="color: rgba(0, 0, 0, 1)"> (e) {
    </span><span style="color: rgba(0, 0, 255, 1)">var</span> item = <span style="color: rgba(0, 0, 255, 1)">this</span><span style="color: rgba(0, 0, 0, 1)">.data.data
    </span><span style="color: rgba(0, 0, 255, 1)">if</span> (item.right &gt;= <span style="color: rgba(0, 0, 255, 1)">this</span>.data.delBtnWidth/2) {
      item.right = <span style="color: rgba(0, 0, 255, 1)">this</span><span style="color: rgba(0, 0, 0, 1)">.data.delBtnWidth
      </span><span style="color: rgba(0, 0, 255, 1)">this</span><span style="color: rgba(0, 0, 0, 1)">.setData({
      isScroll: </span><span style="color: rgba(0, 0, 255, 1)">true</span><span style="color: rgba(0, 0, 0, 1)">,
      data: </span><span style="color: rgba(0, 0, 255, 1)">this</span><span style="color: rgba(0, 0, 0, 1)">.data.data,
      })
    } </span><span style="color: rgba(0, 0, 255, 1)">else</span><span style="color: rgba(0, 0, 0, 1)"> {
      item.right </span>= 0
      <span style="color: rgba(0, 0, 255, 1)">this</span><span style="color: rgba(0, 0, 0, 1)">.setData({
      isScroll: </span><span style="color: rgba(0, 0, 255, 1)">true</span><span style="color: rgba(0, 0, 0, 1)">,
      data: </span><span style="color: rgba(0, 0, 255, 1)">this</span><span style="color: rgba(0, 0, 0, 1)">.data.data,
      })
    }
},

delItem: </span><span style="color: rgba(0, 0, 255, 1)">function</span><span style="color: rgba(0, 0, 0, 1)"> (e) {
      console.log(e)
}
})</span></pre>
</div>
<p>&nbsp;</p>
<p>css部分</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(128, 0, 0, 1)">.order-item </span>{<span style="color: rgba(255, 0, 0, 1)">
    height</span>:<span style="color: rgba(0, 0, 255, 1)"> 240rpx</span>;<span style="color: rgba(255, 0, 0, 1)">
    width</span>:<span style="color: rgba(0, 0, 255, 1)"> 100%</span>;<span style="color: rgba(255, 0, 0, 1)">
    display</span>:<span style="color: rgba(0, 0, 255, 1)"> flex</span>;<span style="color: rgba(255, 0, 0, 1)">
    position</span>:<span style="color: rgba(0, 0, 255, 1)"> relative</span>;
}<span style="color: rgba(128, 0, 0, 1)">
.remove </span>{<span style="color: rgba(255, 0, 0, 1)">
    width</span>:<span style="color: rgba(0, 0, 255, 1)"> 160rpx</span>;<span style="color: rgba(255, 0, 0, 1)">
    height</span>:<span style="color: rgba(0, 0, 255, 1)"> 100%</span>;<span style="color: rgba(255, 0, 0, 1)">
    background-color</span>:<span style="color: rgba(0, 0, 255, 1)"> red</span>;<span style="color: rgba(255, 0, 0, 1)">
    color</span>:<span style="color: rgba(0, 0, 255, 1)"> white</span>;<span style="color: rgba(255, 0, 0, 1)">
    position</span>:<span style="color: rgba(0, 0, 255, 1)"> absolute</span>;<span style="color: rgba(255, 0, 0, 1)">
    top</span>:<span style="color: rgba(0, 0, 255, 1)"> 0</span>;<span style="color: rgba(255, 0, 0, 1)">
    right</span>:<span style="color: rgba(0, 0, 255, 1)"> -160rpx</span>;<span style="color: rgba(255, 0, 0, 1)">
    display</span>:<span style="color: rgba(0, 0, 255, 1)"> flex</span>;<span style="color: rgba(255, 0, 0, 1)">
    justify-content</span>:<span style="color: rgba(0, 0, 255, 1)"> center</span>;<span style="color: rgba(255, 0, 0, 1)">
    align-items</span>:<span style="color: rgba(0, 0, 255, 1)"> center</span>;
}</pre>
</div>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;参考链接:https://www.jianshu.com/p/f9cc446fd328</p>
<p>&nbsp;</p><br><br>
来源:https://www.cnblogs.com/cap-rq/p/11430103.html
頁: [1]
查看完整版本: 微信小程序实现左滑删除效果(原生/uni-app)