vue移动端实现手指滑动效果
作者:qq_40322724 发布时间:2023-07-02 16:48:49
标签:vue,移动端,滑动
本文实例为大家分享了vue移动端实现手指滑动效果的具体代码,供大家参考,具体内容如下
滑动时候黄色块宽度跟着变化
通过touch点击实现
目前感觉宽度变化有点问题,还在思考中
下面上代码:
<template lang="html">
<div class="back" ref="back" @touchstart.prevent="touchStart" @touchmove.prevent="touchMove">
<div class="back-r"
@touchstart.prevent="touchStart" @touchmove.prevent="touchMove"
@touchend="touchEnd"
ref="right"></div>
</div>
</template>
<script>
export default {
data() {
},
created() {
this.touch = {}
},
methods: {
touchStart(e) {
const touch = e.touches[0]
//点击时的位子
this.touch.startX = touch.pageX
this.touch.startY = touch.pageY
console.log('----',this.$refs.right.clientWidth)
},
//开始点击
touchMove(e) {
console.log("move");
const touch = e.touches[0]
//滑动位置和初始位置差
const deltaX = touch.pageX - this.touch.startX
console.log(deltaX)
const deltaY = touch.pageY - this.touch.startY;
//打印right宽度
console.log('----',this.$refs.right.clientWidth+'px')
const rwidth = this.$refs.right.clientWidth
//改变right的宽度
this.$refs.right.style.width = (this.$refs.right.clientWidth + Math.floor(deltaX/50)) +'px'
//进行判断,当宽度小于0或者大于400
if (rwidth<0) {
this.$refs.right.style.width = 0
} else if(rwidth>400){
this.$refs.right.style.width = 400+'px'
}
console.log('----',this.$refs.right.clientWidth+'px')
},
touchEnd() {
console.log("end");
// console.log(this.percent);
}
}
}
</script>
<style scoped lang="stylus" rel="stylesheet/stylus">
body{
margin:0;
padding: 0;
overflow: hidden;
touch-action:none;
}
.back{
width: 100%
height: 100px
border 10px solid #0000FF
overflow: hidden;
}
.back-r{
// display: inline-block
// vertical-align: top
position: relative
width: 400px
height: 100%
overflow: hidden;
background-color: yellow
}
</style>
来源:https://blog.csdn.net/qq_40322724/article/details/105537430


猜你喜欢
- SQLSTATESQL SERVER 驱动程序错误描述 HY000所有绑定列都是只读的。必须是可升级的列,以使用 SQLSetPos 或 S
- 场景昨天系统自动备份了某一个数据库的全部表数据,名dbAll.sql.gz。文件较大(如40G)今天因发现某一个表tableA的一条数据存在
- 在数组中搜索一个特定值,如果找到返回TRUE否则返回FALSE boolean in_array(mixed needle,array ha
- 最近碰见太多次lambda函数了,那就来详细解释一下该函数。lambda函数我们先对lambda函数进行一个简单的介绍lambda函数是一种
- 我们最近的项目中需要使用谷歌机器人验证,这个最主要的就是要有vpn,还需要有公司申请的google账号(自己申请的没用)用于商用的,利用这个
- pyspark 操作hive表pyspark 操作hive表,hive分区表动态写入;最近发现spark动态写入hive分区,和saveAs
- 第一步 关闭代码拼写检查setting–>Inspections–>Spelling–>Typo,取消勾选:第二步 关闭代
- keras 深度学习框架中get_value函数运行越来越慢,内存消耗越来越大问题问题描述如上图所示,经过时间和内存消耗跟踪测试,发现是ke
- 本文实例为大家分享了python学生管理系统开发的具体代码,供大家参考,具体内容如下学生管理系统(基础版)#定义一个函数,显示可以使用的功能
- 本文为大家分享了TensorFLow用Saver保存和恢复变量的具体代码,供大家参考,具体内容如下建立文件tensor_save.py, 保
- 运行代码框<html><META HTTP-EQUIV="Content-Type" content=
- LearningjQuery.com 博客帖子列表的左边有一个很酷的日期,如图:从图中我们看到,“2009”垂直排列在右侧。用Firebug
- for循环基本语法格式: for(初始化变量;条件表达式;操作表达式){  
- Expires 属性 Expires 属性指定了在浏览器上缓冲存储的页距过期还有多少时间。如果用户在某个页过期之前又回到此页,就会显示缓冲区
- 1、按照javaweb项目的要求逐步建立搭建起机构,具体的类包有:model 、db、dao、test;具体的架构详见下图:2、根据搭建的项
- 1.将经常要用到的字段(比如经常要用这些字段来排序,或者用来做搜索),则最好将这些字段设为索引。2.字段的种类尽可能用int 或者tinyi
- 1、shutdown normal 正常方式关闭数据库。 2、shutdown imme
- 本文实例为大家分享了python Tkinter版学生管理的具体代码,供大家参考,具体内容如下Tkinter是python自带的UI包,无需
- 文章所罗列的问题虽然看似简单,但是每个背后都涵盖了一个或几个大家容易忽视的基础知识点,希望能够帮助到你的面试和平时工作。Q1第一个问题关于弱
- 一、什么是字典树在自然语言处理中,字符串集合常用字典树存储,这是一种字符串上的树形数据结构。字典树中每条边都对应一个字,从根节点往下的路径构