3

我在 Windows 8 上使用指针和手势事件时遇到问题。

问题是我无法通过 Javascript 在我的网站上检测到任何手指/手势移动。我确实遵循了微软的指示:http: //msdn.microsoft.com/en-us/library/ie/hh673557 (v=vs.85).aspx 。

但是,看起来即使是最简单的函数也会window.navigator.msPointerEnabled返回null或者false何时返回 a true(因为我使用的是支持触控的 Windows 8 平板电脑)。

以前有人有同样的问题吗?如果是这样,你是如何解决这个问题的?

4

2 回答 2

0
The following example is a basic paint application that works with mouse, touch, and pen via pointer events.

<style>
  html { 
    -ms-touch-action: none; /* Shunt all pointer events to JavaScript code. */
  }
</style>
<canvas id="drawSurface" width="500px" height="500px" style="border:1px solid black;"></canvas>
<script type='text/javascript'>
window.addEventListener('load', function() {
  var canvas = document.getElementById("drawSurface"),
  context = canvas.getContext("2d");
  if (window.navigator.msPointerEnabled) {
    canvas.addEventListener("MSPointerMove", paint, false);
  } 
  else {
    canvas.addEventListener("mousemove", paint, false);
  }
  function paint(event) {
    context.fillRect(event.clientX, event.clientY, 5, 5);
  }
});
</script>

有关更多详细信息,请查看此链接

于 2012-11-05T04:42:42.713 回答
0

除了通常的东西(正确的文档类型和元标记)之外,您还必须设置 -ms-touch-action:none; 在 css 中的 html 和/或 body 元素上:

html, body {
 -ms-touch-action: none;
}

编辑:(MSGestureChange 提供了一个完整的 html 示例

于 2012-12-22T00:19:16.193 回答