uni判斷上下滑動還是左右滑動


最近在做uni-app,要配合插件市場的一款增強版的抽屜做一個在首頁向右滑動抽屜打開想左滑動抽屜關閉的效果,上代碼

<view class="wrapper" @touchstart="fingerstart" @touchend="fingerend">
//...中間是內容
</view>
template區域
export default { data() { return { startData: { clientX: '', clientY: '' }, } }, methods: { fingerstart(e) { this.startData.clientX = e.changedTouches[0].clientX; this.startData.clientY = e.changedTouches[0].clientY; }, fingerend(e) { const subX = e.changedTouches[0].clientX - this.startData.clientX; const subY = e.changedTouches[0].clientY - this.startData.clientY; if (subY > 50 || subY < -50) { if (subY > 50) { console.log('下滑') } else if (subY < -50) { console.log('上滑') } } else { if (subX > 100) { console.log('右滑') } else if (subX < -100) { console.log('左滑') } else { console.log('無效') } } } } }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM