简体   繁体   English

IE10上的触摸点之间的空间

[英]Space between touch points on IE10

I'm working on the plugin flot.touch.js which add touch interactivity (pan and zoom) on the chart for webkit browsers. 我正在使用插件flot.touch.js,它在webkit浏览器的图表上添加了触摸交互性(平移和缩放)。 I want to make it work on IE10 too but I don't know how to retrieve the space between my touch points (I need this for calculate the scale). 我想让它在IE10上工作,但我不知道如何检索我的触摸点之间的空间 (我需要这个来计算比例)。

On webkit browsers, we can do this by using these variables : 在webkit浏览器上,我们可以通过使用这些变量来实现:

evt.originalEvent.touches[0].pageX
evt.originalEvent.touches[0].pagey
evt.originalEvent.touches[1].pageX
evt.originalEvent.touches[1].pageY

With IE's pointer events, a separate event is fired for each touch point. 使用IE的指针事件,会为每个触摸点触发一个单独的事件。 Unlike iOS touch events (as implemented by other browsers too), the state of each "pointer" is tracked separately. 与iOS触摸事件(也由其他浏览器实现)不同,每个“指针”的状态都是单独跟踪的。 Consider it a more generic event that groups several pointer-based input devices. 将其视为一个更通用的事件,它将几个基于指针的输入设备分组。

Each event object is given a pointerId property that can be used to track its state. 每个事件对象都有一个pointerId属性,可用于跟踪其状态。 To track multiple touches, you'll need to store that pointerId along with any other variables in an object outside the scope of the event handler's function, along with any other data you might need. 要跟踪多个触摸,您需要将该pointerId与任何其他变量一起存储在事件处理程序函数范围之外的对象中,以及您可能需要的任何其他数据。 For example: 例如:

var pointers = {};
function pointerDown(evt) {
    if (evt.preventManipulation)
        evt.preventManipulation();

    pointers[evt.pointerId] = [evt.PageX, evt.PageY];

    for (var k in pointers) {
        // loop over your other active pointers
    }
}
function pointerUp(evt) {
    delete pointers[evt.pointerId];
}

Further reading: 进一步阅读:

Like Andy E said. 就像安迪E所说的那样。 Track how many pointers you have on your screen and store properties from each of them (in your case x and y coordinates, acquired form event) 跟踪屏幕上有多少指针并存储每个指针的属性(在您的情况下,x和y坐标,获取的表单事件)

A nice example of multitouch can be found here: http://ie.microsoft.com/testdrive/Graphics/TouchEffects/ and you can go into the code with F12 tools and get all the code under the Script tag: http://ie.microsoft.com/testdrive/Graphics/TouchEffects/Demo.js 多点触控的一个很好的例子可以在这里找到: http//ie.microsoft.com/testdrive/Graphics/TouchEffects/你可以使用F12工具进入代码并获取Script标签下的所有代码: http:// ie.microsoft.com/testdrive/Graphics/TouchEffects/Demo.js

There you can find this part of code: 在那里你可以找到这部分代码:

function addTouchPoint(e) {
    if(touchCount == 0) {
        document.addEventListener(moveevent, moveTouchPoint, false);
    }

    var pID = e.pointerId || 0;
    if(!touchPoints[pID]) {
        touchCount++;
        touchPoints[pID] = {x : e.clientX, y : e.clientY};
    }
}

Hope it helps 希望能帮助到你

If you're on a Windows 8 platform, IE10 supports the MSGesture object. 如果您使用的是Windows 8平台,则IE10支持MSGesture对象。 This object can be used like the iOS version of gesture events. 此对象可以像iOS版本的手势事件一样使用。 To initialize the object, we have to set the target object as well as add the MSPointer on MSPointerDown. 要初始化对象,我们必须设置目标对象以及在MSPointerDown上添加MSPointer。 For example: 例如:

var myGesture = new MSGesture();
var myElement = document.getElementById("MyCanvas");
myGesture.target = myElement;  //sets target
myElement.addEventListener("MSPointerDown", function (event){
   redGesture.addPointer(evt.pointerId);  // adds pointer to the MSGesture object
}, false);  

From here, you can add an event listener for the MSGestureChange function to process the event.scale property. 从这里,您可以为MSGestureChange函数添加一个事件侦听器来处理event.scale属性。 Note that if the target is not set, an InvalidStateError exception will occur. 请注意,如果未设置目标,则会发生InvalidStateError异常。

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

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