vue移動(dòng)端實(shí)現(xiàn)手指滑動(dòng)效果
本文實(shí)例為大家分享了vue移動(dòng)端實(shí)現(xiàn)手指滑動(dòng)效果的具體代碼,供大家參考,具體內(nèi)容如下

滑動(dòng)時(shí)候黃色塊寬度跟著變化
通過touch點(diǎn)擊實(shí)現(xiàn)
目前感覺寬度變化有點(diǎn)問題,還在思考中
下面上代碼:
<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]
//點(diǎn)擊時(shí)的位子
this.touch.startX = touch.pageX
this.touch.startY = touch.pageY
console.log('----',this.$refs.right.clientWidth)
},
//開始點(diǎn)擊
touchMove(e) {
console.log("move");
const touch = e.touches[0]
//滑動(dòng)位置和初始位置差
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
//改變r(jià)ight的寬度
this.$refs.right.style.width = (this.$refs.right.clientWidth + Math.floor(deltaX/50)) +'px'
//進(jìn)行判斷,當(dāng)寬度小于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>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Vue實(shí)現(xiàn)移動(dòng)端左右滑動(dòng)效果的方法
- vue自定義移動(dòng)端touch事件之點(diǎn)擊、滑動(dòng)、長(zhǎng)按事件
- vue2.0移動(dòng)端滑動(dòng)事件vue-touch的實(shí)例代碼
- vue移動(dòng)端的左右滑動(dòng)事件詳解
- 寫一個(gè)移動(dòng)端慣性滑動(dòng)&回彈Vue導(dǎo)航欄組件 ly-tab
- vue實(shí)現(xiàn)一個(gè)移動(dòng)端屏蔽滑動(dòng)的遮罩層實(shí)例
- vue2.0 better-scroll 實(shí)現(xiàn)移動(dòng)端滑動(dòng)的示例代碼
- vue移動(dòng)端實(shí)現(xiàn)手機(jī)左右滑動(dòng)入場(chǎng)動(dòng)畫
- 移動(dòng)端滑動(dòng)切換組件封裝 vue-swiper-router實(shí)例詳解
- vue3實(shí)現(xiàn)移動(dòng)端滑動(dòng)模塊
相關(guān)文章
Vue實(shí)現(xiàn)頁(yè)面添加滿屏水印和去除水印功能
在一些特殊的應(yīng)用場(chǎng)景中,可能需要在網(wǎng)頁(yè)上添加水印以保護(hù)版權(quán)或標(biāo)識(shí)信息,本文將介紹如何在Vue項(xiàng)目中添加滿屏水印并實(shí)現(xiàn)去除水印的功能,文中通過代碼示例講解的非常詳細(xì),需要的朋友可以參考下2024-07-07
Vue數(shù)據(jù)更新但頁(yè)面沒有更新的多種情況問題及解決
這篇文章主要介紹了Vue數(shù)據(jù)更新但頁(yè)面沒有更新的多種情況問題及解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-07-07
Vue?vant使用ImagePreview實(shí)現(xiàn)預(yù)覽圖片
這篇文章主要介紹了Vue?vant使用ImagePreview實(shí)現(xiàn)預(yù)覽圖片,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-10-10
Vue.js如何優(yōu)雅的進(jìn)行form validation
Vue.js如何優(yōu)雅的進(jìn)行form validation,針對(duì)此問題,給出了多個(gè)網(wǎng)友的回答,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-04-04
vuex + axios 做登錄驗(yàn)證 并且保存登錄狀態(tài)的實(shí)例
今天小編就為大家分享一篇vuex + axios 做登錄驗(yàn)證 并且保存登錄狀態(tài)的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-09-09
基于canvas實(shí)現(xiàn)手寫簽名(vue)
這篇文章主要為大家詳細(xì)介紹了基于canvas實(shí)現(xiàn)簡(jiǎn)易的手寫簽名,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-05-05
Vue使用ElemenUI對(duì)table的指定列進(jìn)行合算的方法
這篇文章主要介紹了Vue使用ElemenUI對(duì)table的指定列進(jìn)行合算的方法,本文結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下2023-03-03

