移动端判断手指的滑动方向
小程序中,不能够使用v-show; 因为v-show是让dom节点显示或者隐藏的;在小程序中是没有dom节点
使用v-if;因为v-if在内存中动态创建或者销毁的
<template>
<view class="list-page">
<!-- @touchstart触摸开始,多点触控,后面的手指同样会触发; @touchmove 触摸点改变滑动时; touchend触摸结束,手指离开屏幕时;-->
<text @touchstart="handletouchstart" @touchend="handletouchend" @touchmove="handletouchmove" class="demo1" v-for="(item,index) in arrList" :key="index">
{{ item.cont}}-{{text}}=={{cont}}
</text>
<add-cricle-btn v-if="showFlag"></add-cricle-btn>
</view>
</template>
<script>
<script>
import cricleBtn from "../../components/add-cricle-btn.vue"
export default {
data() {
return {
arrList:[
{cont:"13123"},
{cont:"13123"},
{cont:"13123"},
{cont:"13123"},
{cont:"13123"},
{cont:"13123"},
{cont:"13123"},
{cont:"13123"},
{cont:"13123"},
{cont:"13123"},
{cont:"13123"},
{cont:"13123"},
{cont:"13123"},
{cont:"13123"},
{cont:"13123"},
{cont:"13123"}
],
flag: 0,
text: '',
lastX: 0,
lastY: 0,
cont:"",
showFlag:true,
}
},
methods: {
// 接触点改变,滑动时
handletouchmove: function(event) {
if (this.flag !== 0) {
return;
}
this.cont="覆膜开始"
console.log(event)
let currentX = event.touches[0].pageX;
let currentY = event.touches[0].pageY;
let tx = currentX - this.lastX;
let ty = currentY - this.lastY;
let text = '';
this.mindex = -1;
//左右方向滑动
if (Math.abs(tx) > Math.abs(ty)) {
if (tx < 0) {
text = '向左滑动';
this.flag = 1;
} else if (tx > 0) {
text = '向右滑动';
this.flag = 2;
}
}
//上下方向滑动
else {
if (ty < 0) {
text = '向上滑动';
this.flag = 3;
this.showFlag=false;
} else if (ty > 0) {
text = '向下滑动';
this.flag = 4;
this.showFlag=true;
}
}
//将当前坐标进行保存以进行下一次计算
this.lastX = currentX;
this.lastY = currentY;
this.text = text;
},
// 开始滑动
handletouchstart: function(event) {
this.lastX = event.touches[0].pageX;
this.lastY = event.touches[0].pageY;
},
// 滑动结束结束
handletouchend: function(event) {
this.flag = 0;
// this.text = '没有滑动';
},
},
components:{
'add-cricle-btn':cricleBtn
}
}
</script>
<style scoped>
.list-page{
display: flex;
flex-direction: column;
}
.demo1{
height: 100rpx;
line-height: 100rpx;
text-align: center;
color: lightpink;
font-size: 30rpx;
border-bottom: 1px solid lightpink;
}
</style>
遇见问题,这是你成长的机会,如果你能够解决,这就是收获。
作者:晚来南风晚相识
出处:https://www.cnblogs.com/IwishIcould/
本文版权归作者所有,欢迎转载,未经作者同意须保留此段声明,在文章页面明显位置给出原文连接
如果文中有什么错误,欢迎指出。以免更多的人被误导。
出处:https://www.cnblogs.com/IwishIcould/
想问问题,打赏了卑微的博主,求求你备注一下的扣扣或者微信;这样我好联系你;(っ•̀ω•́)っ✎⁾⁾!
如果觉得这篇文章对你有小小的帮助的话,记得在右下角点个“推荐”哦,或者关注博主,在此感谢!
万水千山总是情,打赏5毛买辣条行不行,所以如果你心情还比较高兴,也是可以扫码打赏博主(っ•̀ω•́)っ✎⁾⁾!
想问问题,打赏了卑微的博主,求求你备注一下的扣扣或者微信;这样我好联系你;(っ•̀ω•́)っ✎⁾⁾!

支付宝

微信
如果文中有什么错误,欢迎指出。以免更多的人被误导。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
2019-07-21 echarts的使用
2019-07-21 01-day-vuex的使用