admin管理员组文章数量:1318580
I'm making an app to draw inside an HTML5 canvas
, but I can not do it from the mobile or tablet.
I can not avoid the browser's native scroll or chrome refresh when pushed down
I have created an example in jsfiddle so you can see it.
I'm making an app to draw inside an HTML5 canvas
, but I can not do it from the mobile or tablet.
I can not avoid the browser's native scroll or chrome refresh when pushed down
I have created an example in jsfiddle so you can see it.
Share Improve this question edited Jan 4, 2017 at 17:53 Heretic Monkey 12.1k7 gold badges61 silver badges131 bronze badges asked Jan 4, 2017 at 17:15 DiV666DiV666 1092 silver badges12 bronze badges 1- Please provide all relevant code in an minimal reproducible example in the question itself, not on a third-party site. – Heretic Monkey Commented Jan 4, 2017 at 17:53
2 Answers
Reset to default 6To suppress default UA behaviour you need to add the CSS property touch-action: none
to the canvas element.
touch-action
specifies if and how a HTML element should respond to gestures. With touch-action: none
no UA behaviour is triggered (e.g. dragging or zooming). The default property is touch-action: auto
, which allows all UA behaviour to be triggered.
This looks like a genuine Chrome bug, which I will report using your sample code. Setting a touch-action in CSS isn't a solution if you want to dynamically decide in JavaScript whether to handle the pointerMove with your own code vs. allow the native browser handling.
If you set touch-action: "none", then the native browser handling will never run. Conversely, as you've reported, having no touch-action setting, which is equivalent to the default of "auto", won't work because Chrome ignores calls to preventDefault() on pointerMove and still calls pointerCancel - a bug.
Note that if you added a listener for touchMove instead, using the passive: false flag, then preventDefault() would work as expected, avoiding touchCancel. However, then you've got to use separate mouse event and touch event listeners, which is what you're trying to avoid by using pointer events.
本文标签: javascriptpreventdefault and stoppropagation not working with pointermoveStack Overflow
版权声明:本文标题:javascript - preventdefault and stoppropagation not working with pointermove - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742044855a2417721.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论