基于vue框架怎样制作移动端滑动的效果
Admin 2022-07-11 群英技术资讯 1229 次浏览
很多朋友都对“基于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>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
这篇文章主要为大家详细介绍了VUE使用canvas实现签名组件,兼容PC移动端,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
这篇文章主要为大家介绍了vue组件通信的几种方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下,希望能够给你带来帮助
generator函数是JS引擎中使用的结构函数,不提供给开发者。由构造函数generator创建的对象是迭代器和可迭代对象。
这篇文章我们来了解jQuery触发change事件的方法,手动触发改变事件我们需要使用到change()方法,接下来我们通过示例来了解change()方法的使用及触发改变事件的实现,感兴趣的朋友就继续往下看吧。
这篇文章主要介绍了详解vue实现坐标拾取器功能示例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
成为群英会员,开启智能安全云计算之旅
立即注册关注或联系群英网络
7x24小时售前:400-678-4567
7x24小时售后:0668-2555666
24小时QQ客服
群英微信公众号
CNNIC域名投诉举报处理平台
服务电话:010-58813000
服务邮箱:service@cnnic.cn
投诉与建议:0668-2555555
Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 ICP核准(ICP备案)粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008