日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

修复BUG的完整过程:Ignored attempt to cancel a touchend event with cancelable=false

發布時間:2024/3/13 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 修复BUG的完整过程:Ignored attempt to cancel a touchend event with cancelable=false 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

代碼環境

"vue": "^3.2.33", "swiper": "^8.4.2",

Bug表現:

<swiper-slide>包含<video>元素,鼠標落在<video>元素拖動時,控制臺報錯,swiper無法正常拖動

調試過程:

1、查看錯誤發生的調用順序:可以看到是因為palyer的onElementTouchend事件導致

2、提煉關鍵字并搜索
(1)方案一:修改swiper源碼(不采用)
(2)方案二:touch-action: false(無效)

3、去除可能干擾判斷的元素,判斷問題來源
(1)去除<video>,swiper表現正常
(2)仔細觀察發現頁面高度溢出并可滾動

4、推測發生原因:
<swiper-slide>內的元素高度超過外層元素的高度,并設置了可滾動,在手指上下劃動時,觸發了元素滾動,從而導致swiper切換失敗

5、修復問題并測試

6、swiper監聽touchend事件,處理業務邏輯

<swiper @touchStart="($el, e) => touchstart(e)" @touchEnd="($el, e) => touchend(e)" @slideChangeTransitionEnd="onTransitionEnd" >// 手指按下 let touchstartY = 0 function touchstart(e: any) {touchstartY = e.changedTouches[0]?.clientY || 0 } // 手指松開 function touchend(e: any) {const touchendY = e.changedTouches[0]?.clientYif (touchstartY - touchendY > 80) {// 下一個視頻swiperRef.value?.slideTo?.(2, 300, true)} else if (touchendY - touchstartY > 80) {// 上一個視頻swiperRef.value?.slideTo?.(0, 300, true)}touchstartY = 0 } // swipe切換的過渡動畫結束時,回到放置播放器的swiper-slide // 在這個節點復位可以讓用戶感知到視頻在切換 function onTransitionEnd(e: any) {videoStore.getShortVideo(active.value === 1 ? '0' : '1' )swiperRef.value?.slideTo?.(1, 0, false) }

總結

以上是生活随笔為你收集整理的修复BUG的完整过程:Ignored attempt to cancel a touchend event with cancelable=false的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。