uniapp实现页面左右滑动,上下滑动事件

忘是亡心i 2022-11-18 02:29 687阅读 0赞

实现代码:

  1. <view class="" @touchstart="touchstart" @touchend="touchend">
  2. </view>
  3. data() {
  4. return {
  5. touchData: {}, //滑动事件数据
  6. }
  7. }
  8. methods: {
  9. touchstart(e) {
  10. this.touchData.clientX = e.changedTouches[0].clientX;
  11. this.touchData.clientY = e.changedTouches[0].clientY;
  12. },
  13. touchend(e) {
  14. const subX = e.changedTouches[0].clientX - this.touchData.clientX;
  15. const subY = e.changedTouches[0].clientY - this.touchData.clientY;
  16. if(subY > 50){
  17. console.log('下滑')
  18. }
  19. if(subY < -50){
  20. console.log('上滑')
  21. }
  22. if (subX > 50) {
  23. console.log('右滑')
  24. }
  25. if (subX > -50) {
  26. console.log('左滑')
  27. }
  28. },
  29. }

发表评论

表情:
评论列表 (有 0 条评论,687人围观)

还没有评论,来说两句吧...

相关阅读