实现效果

  1. 列表中侧滑删除
  2. 删除不同时存在
  3. scrollview上下滑动与侧滑删除不影响

uni-app实现

html部分

<template>
<scroll-view :scroll-y="isScroll" :style="{ height: windowHeight + 'px' }">
<block :key="index" v-for="(item, index) in dataList">
<view :data-index="index" class="order-item" @touchstart="drawStart" @touchmove="drawMove" @touchend="drawEnd" :style="{ right: item.right + 'rpx' }">
<view class="content">{{ item.content }}</view>
<view class="remove" @click="delItem">删除</view>
</view>
</block>
</scroll-view>
</template>

js部分

<script>
export default {
data() {
return {
delBtnWidth: 160,
dataList: [
{ content: '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 }
],
isScroll: true,
windowHeight: 0
};
},
onLoad: function(options) {
var that = this;
wx.getSystemInfo({
success: function(res) {
that.windowHeight = res.windowHeight;
}
});
},
methods: {
drawStart: function(e) {
// console.log("drawStart");
var touch = e.touches[0];
for (var index in this.dataList) {
this.dataList[index].right = 0;
}
this.startX = touch.clientX;
},
drawMove: function(e) {
var touch = e.touches[0];
var item = this.dataList[e.currentTarget.dataset.index];
var disX = this.startX - touch.clientX; if (disX >= 20) {
if (disX > this.delBtnWidth) {
disX = this.delBtnWidth;
}
this.isScroll = false;
this.dataList[e.currentTarget.dataset.index].right = disX;
} else {
this.isScroll = true;
this.dataList[e.currentTarget.dataset.index].right = 0;
}
},
drawEnd: function(e) {
var item = this.dataList[e.currentTarget.dataset.index];
if (item.right >= this.delBtnWidth / 2) {
this.isScroll = true;
this.dataList[e.currentTarget.dataset.index].right = this.delBtnWidth;
} else {
this.isScroll = true;
this.dataList[e.currentTarget.dataset.index].right = 0;
}
},
delItem() {
console.log('删除');
}
}
};
</script>

css样式

<style scoped>
.order-item {
height: 240rpx;
width: 100%;
display: flex;
position: relative;
} .remove {
width: 160rpx;
height: 100%;
background-color: red;
color: white;
position: absolute;
top:;
right: -160rpx;
display: flex;
justify-content: center;
align-items: center;
}
</style>

小程序原生开发

html部分

<scroll-view scroll-y="{{isScroll}}" style='height:{{windowHeight}}px'>
<block wx:key="item" wx:for="{{data}}">
<view data-index='{{index}}' class="order-item" bindtouchstart="drawStart" bindtouchmove="drawMove" bindtouchend="drawEnd" style="right:{{item.right}}rpx">
<view class="content">{{item.content}}</view>
<view class="remove" bindtap="delItem">删除 </view>
</view>
</block>
</scroll-view>

js部分

Page({
data: {
delBtnWidth:160,
data: [{ content: "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 }],
isScroll:true,
windowHeight:0,
},
onLoad: function (options) {
var that = this;
wx.getSystemInfo({
success: function (res) {
that.setData({
windowHeight: res.windowHeight
});
}
});
},
drawStart: function (e) {
// console.log("drawStart");
var touch = e.touches[0] for(var index in this.data.data) {
var item = this.data.data[index]
item.right = 0
}
this.setData({
data: this.data.data,
startX: touch.clientX,
}) },
drawMove: function (e) {
var touch = e.touches[0]
var item = this.data.data[e.currentTarget.dataset.index]
var disX = this.data.startX - touch.clientX if (disX >= 20) {
if (disX > this.data.delBtnWidth) {
disX = this.data.delBtnWidth
}
item.right = disX
this.setData({
isScroll: false,
data: this.data.data
})
} else {
item.right = 0
this.setData({
isScroll: true,
data: this.data.data
})
}
},
drawEnd: function (e) {
var item = this.data.data[e.currentTarget.dataset.index]
if (item.right >= this.data.delBtnWidth/2) {
item.right = this.data.delBtnWidth
this.setData({
isScroll: true,
data: this.data.data,
})
} else {
item.right = 0
this.setData({
isScroll: true,
data: this.data.data,
})
}
}, delItem: function (e) {
console.log(e)
}
})

css部分

.order-item {
height: 240rpx;
width: 100%;
display: flex;
position: relative;
}
.remove {
width: 160rpx;
height: 100%;
background-color: red;
color: white;
position: absolute;
top:;
right: -160rpx;
display: flex;
justify-content: center;
align-items: center;
}

参考链接:https://www.jianshu.com/p/f9cc446fd328

微信小程序实现左滑删除效果(原生/uni-app)的更多相关文章

  1. 微信小程序实现左滑删除源码

    左滑删除效果在app的交互方式中十分流行,比如全民应用微信 微信左滑删除 再比如曾引起很大反响的效率app Clear Clear左滑删除 从技术上来说,实现这个效果并不困难,响应一下滑动操作,移动一 ...

  2. 微信小程序实现标签页滑块效果

    微信小程序实现标签页滑块效果 小程序完整代码: wxml: <view class="swiper-tab"> <view class="swiper- ...

  3. 微信小程序里实现跑马灯效果

    在微信小程序 里实现跑马灯效果,类似滚动字幕或者滚动广告之类的,使用简单的CSS样式控制,没用到JS wxml: <!-- 复制的跑马灯效果 --> <view class=&quo ...

  4. Taro UI开发小程序实现左滑喜欢右滑不喜欢效果

    前言:年后入职了一家新公司,与前同事交接完之后,发现公司有一个四端的项目(iOS,Android,H5,小程序),iOS和安卓都实现了左滑右滑的效果,而h5和小程序端没实现,询问得知前同事因网上没找到 ...

  5. 微信小程序实现左侧滑栏

    前言 一直想给项目中的小程序设置侧滑栏,将退出按钮放到侧滑中,但是小程序没有提供相应的控件和API,因此只能自己手动实现,网上很多大神造的轮子很不错,本文就在是站在巨人的肩膀上实现. 效果 先看看效果 ...

  6. 微信小程序:scroll滑到指定位置

    概述 这是我开发微信小程序遇到的坑中的一个,专门记录下来,供以后开发时参考,相信对其他人也有用. scroll滑到指定位置,有两种解决方案,一种是用scroll-view标签,另一种是用wx.page ...

  7. 图解微信小程序---实现行的删除和增加操作

    图解微信小程序之实现行的删除和增加操作 代码笔记部分 第一步:在项目的app.json中创建一个新的页面(页面名称英文,可自定义) 第二步:在创建的新页面中编写页面(注意bindtap属性值,因为是我 ...

  8. 使用zepto实现QQ消息左滑删除效果

    有这样一个需求: 1. 有一个列表,将每一个列表项左滑动出现删除按钮: 2. 右滑动隐藏删除按钮: 3. 点击这个删除按钮删除该列表项. 完成以后的效果: 这是微信网页端的页面,使用的是 zepto ...

  9. 微信小程序:上滑触底加载下一页

    给商品列表页面添加一个上滑触底加载下一页的效果,滚动条触底之后就发送一个请求,来加载下一页数据, 先在getGoodsList中获取总条数 由于总页数需要再另外的一个方法中使用,所以要把总页数变成一个 ...

随机推荐

  1. <c:foreach>指定循环次数

    <c:forEach begin="0" end="4" var="i"> <c:set var="ans&qu ...

  2. Python 基础之linux基础相关

    一: python3.6.x在Ubuntu16.04下安装过程 #(1)保证网络正常连接 sudo add-apt-repository ppa:jonathonf/python-3.6  (如果超时 ...

  3. 【转】彻底搞透Netty框架

    本文基于 Netty 4.1 展开介绍相关理论模型,使用场景,基本组件.整体架构,知其然且知其所以然,希望给大家在实际开发实践.学习开源项目方面提供参考. Netty 是一个异步事件驱动的网络应用程序 ...

  4. 吴裕雄--天生自然HADOOP操作实验学习笔记:hbase简介

    实验目的 了解hbase的概念 通过安装hbase了解hbase的原理 了解hbase与hadoop的关系 复习hadoop和zookeeper的运行 实验原理 hbase是bigtable的开源山寨 ...

  5. HTML多条件筛选商品

    今天同事接到一个类似于JD的按条件筛选商品的功能,同事把这个锅出色的甩给了我,俺就勉为其难的解决了这个问题. 首先我们来理清一下思路: 1.条件切换时,tab选项卡肯定要跟着切换,而且只是一个大类条件 ...

  6. hibernate中简单的增删改查

    项目的整体结构如下 1.配置文件 hibernate.cfg.xml <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hi ...

  7. struts2--action请求与Action类

    1.action:代表一个sturts2的请求: 2.Action类:能够处理Struts2请求的类: --属性名必须遵守与JavaBean属性名相同的命名规则: --属性的类型可以使任意类型.从字符 ...

  8. centos6忘记root密码

    Centos6 1.在开机时不要自动进入系统,按任意键进入GRUB引导菜单 2.按E键进入编辑模式 3.选中kernel选项继续按E键 4.在结尾处添加single关键字后按ENTER保存退出 5.之 ...

  9. 1-4SpringBoot操作之Spring-Data-Jpa(一)

    Spring-Data-Jpa JPA(Java Persistence API)定义了一系列对象持久化的标准, 目前实现这一规范的产品有Hibernate.TopLink等. Spring Data ...

  10. 每个项目中,你必须知道的11个Java第三方类库。

    Java第三方library ecosystem是一个很广阔的范畴.不久前有人撰文:每个项目中,你必须知道的11个Java第三方类库. 单元测试 1.DBUnit DBunit是一个基于junit扩展 ...