简体   繁体   English

preventdefault和stoppropagation不适用于pointermove

[英]preventdefault and stoppropagation not working with pointermove

I'm making an app to draw inside an HTML5 canvas , but I can not do it from the mobile or tablet. 我正在制作一个可在HTML5 canvas内绘制的应用程序,但无法在移动设备或平板电脑上完成。

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. 我在jsfiddle中创建了一个示例,因此您可以看到它。

To suppress default UA behaviour you need to add the CSS property touch-action: none to the canvas element. 要取消默认的UA行为,您需要将CSS属性touch-action: none到canvas元素。

touch-action specifies if and how a HTML element should respond to gestures. touch-action指定HTML元素是否以及如何响应手势。 With touch-action: none no UA behaviour is triggered (eg dragging or zooming). 使用touch-action: none没有触发任何UA行为(例如,拖动或缩放)。 The default property is touch-action: auto , which allows all UA behaviour to be triggered. 默认属性是touch-action: auto ,它允许触发所有UA行为。

This looks like a genuine Chrome bug, which I will report using your sample code. 这看起来像是一个真正的Chrome错误,我将使用您的示例代码进行报告。 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. 如果您想在JavaScript中动态地决定是否使用自己的代码来处理pointerMove与允许本地浏览器来处理,则在CSS中设置触摸动作不是解决方案。

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. 相反,正如您所报告的那样,没有触摸操作设置(相当于默认的“自动”)将无法正常工作,因为Chrome会忽略对pointerMove上的preventDefault()的调用,并且仍会调用pointerCancel-一个错误。

Note that if you added a listener for touchMove instead, using the passive: false flag, then preventDefault() would work as expected, avoiding touchCancel. 请注意,如果改为使用passive:false标志为touchMove添加侦听器,则preventDefault()将按预期工作,从而避免了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. 但是,您必须使用单独的鼠标事件和触摸事件侦听器,而这正是通过使用指针事件来避免的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM