vue移動端實現(xiàn)手指滑動效果
更新時間:2021年06月29日 08:30:20 作者:qq_40322724
這篇文章主要為大家詳細介紹了vue移動端實現(xiàn)手指滑動效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了vue移動端實現(xiàn)手指滑動效果的具體代碼,供大家參考,具體內(nèi)容如下
滑動時候黃色塊寬度跟著變化
通過touch點擊實現(xià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] //點擊時的位子 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' //進行判斷,當(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>
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Vue數(shù)據(jù)更新但頁面沒有更新的多種情況問題及解決
這篇文章主要介紹了Vue數(shù)據(jù)更新但頁面沒有更新的多種情況問題及解決,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-07-07Vue?vant使用ImagePreview實現(xiàn)預(yù)覽圖片
這篇文章主要介紹了Vue?vant使用ImagePreview實現(xiàn)預(yù)覽圖片,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-10-10Vue.js如何優(yōu)雅的進行form validation
Vue.js如何優(yōu)雅的進行form validation,針對此問題,給出了多個網(wǎng)友的回答,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-04-04vuex + axios 做登錄驗證 并且保存登錄狀態(tài)的實例
今天小編就為大家分享一篇vuex + axios 做登錄驗證 并且保存登錄狀態(tài)的實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-09-09Vue使用ElemenUI對table的指定列進行合算的方法
這篇文章主要介紹了Vue使用ElemenUI對table的指定列進行合算的方法,本文結(jié)合實例代碼給大家介紹的非常詳細,需要的朋友可以參考下2023-03-03