javascript 触摸 API(例如 touchstart)在 MS Edge 中不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33300962/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Touch API (e.g. touchstart) not working in MS Edge
提问by dude
my application is using the Touch API to detect touch events in JavaScript. Example:
我的应用程序使用 Touch API 来检测 JavaScript 中的触摸事件。例子:
$(".element").on("touchstart", function(event){
alert("TRUE");
});
This works on any touch device with any browser like Android or iOS, however it doesn't work in MS Edge on a Windows 10 Tablet with or without conntected keyboard. The API seems to be supported: Compatibility list. However, I've tested: 'ontouchstart' in window
and this returns false on this device. Furthermore mousedown
seems to get fired.
这适用于任何带有任何浏览器(如 Android 或 iOS)的触摸设备,但它不适用于带有或不带有连接键盘的 Windows 10 平板电脑上的 MS Edge。API 似乎受支持:Compatibility list。但是,我已经测试过:'ontouchstart' in window
这在此设备上返回 false。此外mousedown
似乎被解雇了。
What is going on here? What can I do to fire touch events on a Windows 10 tablet? I would like to keep the event only for touch devices. Switching to the Pointer Events API would include also Desktop devices and that is not what I want.
这里发生了什么?如何在 Windows 10 平板电脑上触发触摸事件?我想仅针对触摸设备保留该事件。切换到指针事件 API 还包括桌面设备,这不是我想要的。
采纳答案by t.ouvre
for touch API, you have to activate a flag on Edge : in the address bar, enter about:flags and press enter. In the section Touch, you can enable touch events with the corresponding dropdown
对于触摸 API,您必须在 Edge 上激活一个标志:在地址栏中,输入 about:flags 并按 Enter。在 Touch 部分,您可以使用相应的下拉菜单启用触摸事件
回答by t.ouvre
Did you enable custom touch handling ? You can do it with the following css snippet (on the body tag or just a container for geastures) :
您是否启用了自定义触摸处理?您可以使用以下 css 片段(在 body 标签上或只是一个手势容器)来做到这一点:
-ms-touch-action: none;
Next, touch API is a webkit feature (maybe there is an error in CanIuse ?). IE and Edge have a similar feature known as Pointer API. But you can use a polyfill library like this : https://github.com/CamHenlin/TouchPolyfill
接下来,touch API 是一个 webkit 功能(可能是 CanIuse 有错误?)。IE 和 Edge 有一个类似的特性,称为指针 API。但是你可以使用这样的 polyfill 库:https: //github.com/CamHenlin/TouchPolyfill
回答by Shanoor
Try using the pointerdown
event. Some (much) more information. As you can see, touchstart
is triggered by Edge but not in all configurations, when a keyboard is attached/paired for example, no touchstart
.
尝试使用该pointerdown
事件。一些(更多)信息。如您所见,touchstart
由 Edge 触发,但并非在所有配置中,例如,当连接/配对键盘时,没有touchstart
.