【小程序問題】微信小程序 在canvas畫布上划動 頁面跟着滑動

微信小程序官方文檔有說明,disable-scroll="true" 能夠阻止頁面下拉和滾動。這裏有個坑,disable-scroll在真機上若是要生效,那麼要給canvas綁定一個觸摸事件才能生效。canvas

<canvas disable-scroll="true" bindtouchmove="touchMove"></canvas>

順便說一下canvas觸摸事件的坑,在canvas上必定要綁定三個觸摸事件真機才能響應到畫布觸摸的event。bindtouchstart/bindtouchmove/bindtouchend,只綁定兩個或一個會致使真機獲取不到canvas上的觸摸事件。。。。。花了好長時間來找這個bug出現的緣由。。。也是醉了
<canvas disable-scroll="true" bindtouchstart="touchStart" bindtouchmove="touchMove" bindtouchend="touchEnd" canvas-id="canvas" class="canvas"></canvas>
做者:山中有一郎 連接:https://www.zhihu.com/question/52852717/answer/132623677 來源:知乎 著做權歸做者全部。商業轉載請聯繫做者得到受權,非商業轉載請註明出處。