微信小程序官方文档有说明,disable-scroll="true" 可以阻止页面下拉和滚动。这里有个坑,disable-scroll在真机上如果要生效,那么要给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
来源:知乎
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。