javascript touchmove/MSPointerMove 事件未在 Windows 8 中触发

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12057946/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 15:11:47  来源:igfitidea点击:

touchmove/MSPointerMove event not firing in Windows 8

javascripttouchwindows-8tabletinternet-explorer-10

提问by methusalem

I'm just a lowly uC programmer who's trying to put together a little web interface for his boss. I've got everything working so far except being able to select a square on a canvas using touch input.

我只是一个卑微的 uC 程序员,他正试图为他的老板组装一个小网络界面。到目前为止,除了能够使用触摸输入在画布上选择一个正方形之外,我已经完成了所有工作。

This is on a Samsung Slate 7 tablet running Windows 8 and IE10

这是在运行 Windows 8 和 IE10 的三星 Slate 7 平板电脑上

I've distilled the code down to pretty much the bare essentials here:

我已经将代码提炼为几乎最基本的要素:

var cxt;
var c;

window.onload = function () {

c = document.getElementById('displayCanvas');

cxt = c.getContext('2d');


/*
c.addEventListener("MSPointerUp", mouseUp, false);
c.addEventListener("MSPointerMove", mouseMove, false);
c.addEventListener("MSPointerDown", mouseDown, false);
*/
c.addEventListener("touchend", mouseUp, false)
c.addEventListener("touchmove", mouseMove, false);
c.addEventListener("touchstart", mouseDown, false);

}


function mouseDown(downE) {
    window.console &&  console.log("down");
};


function mouseMove(moveE){
    window.console && console.log("move");
}


function mouseUp() {
    window.console && console.log("end");
}

I get both the start and end events, using both the MSPointer and the "normal" javascript touch events, however the "move" event doesn't register.

我同时使用 MSPointer 和“普通”javascript 触摸事件获取开始和结束事件,但是“移动”事件未注册。

I'm sure it's something really simple I'm missing here, thanks for helping me out!

我确定这是我在这里想念的非常简单的东西,谢谢你的帮助!

回答by Glen Gordon

I'm assuming you are interacting with the HTML page in desktop IE on Windows 8. In desktop IE, the MSPointerMove is not firing on that canvas because the default behavior when the user moves their finger around on the screen is to pan the content. If you style the canvas with the following snippet your MSPointerMove event should be detected.

我假设您正在与 Windows 8 上的桌面 IE 中的 HTML 页面进行交互。在桌面 IE 中,MSPointerMove 不会在该画布上触发,因为用户在屏幕上移动手指时的默认行为是平移内容。如果您使用以下代码段设置画布样式,则应检测到您的 MSPointerMove 事件。

style="-ms-touch-action: none"

style="-ms-touch-action: 无"

Here's a great article on how to get touch working on many browsers. http://blogs.msdn.com/b/ie/archive/2011/10/19/handling-multi-touch-and-mouse-input-in-all-browsers.aspx

这是一篇关于如何在许多浏览器上使用触控的很棒的文章。http://blogs.msdn.com/b/ie/archive/2011/10/19/handling-multi-touch-and-mouse-input-in-all-browsers.aspx

回答by robocat

The Samsung Slate 7 tablets have a bug in older versions of the drivers that might be relevant. I saw another answer tagged [internet-explorer-10] that had the details. Have you updated your driver?

三星 Slate 7 平板电脑在旧版本的驱动程序中存在可能相关的错误。我看到了另一个标记为 [internet-explorer-10] 的答案,其中包含详细信息。你更新驱动了吗?