Javascript & iPad touch event.identifier is continually incrementing

I'm building a simple web game with mouse and touch support. Based on the accepted answer to JavaScript mapping touch events to mouse events I copy-pasted their code (with a couple of modifications).

I'm mapping the first touch the user makes to a left-click event, and the second they make (with the first touch held down) to a right-click event. Like so:

function touchHandler(event){
var touches = event.changedTouches;
var first   = touches[0];
var type    = "";

switch(event.type){
    case "touchstart" : type = "mousedown"; break;
    case "touchmove"  : type = "mousemove"; break;
    case "touchend"   : type = "mouseup";   break;
    default:return;
}
var button = 0;
if(first.identifier >= 1)
    button = 2;
document.getElementById("foo").innerHTML = first.identifier; //my "debug statement"
var simulatedEvent = document.createEvent("MouseEvent");
simulatedEvent.initMouseEvent(type,true,true,window,1,
                              first.screenX,first.screenY,
                              first.clientX,first.clientY,false,
                              false,false,false,button,null);
first.target.dispatchEvent(simulatedEvent);
event.preventDefault(); }

Here's the issue: my "debug statement" (see the code) revealed that identifier was being correct in the emulator modes in chrome, as well as on my android phone and MS Surface. But on my iPad? 1862464270, and counting. Clearly, I do not have that many fingers.

This issue occurs running either Chrome or Safari, but only on my iPad. Everything works fine on the other systems I've used for testing.

Does anyone have an idea of what might be causing this issue? Has anyone else encountered strange event.identifier behavior?

链接地址: http://www.djcxy.com/p/17128.html

上一篇: iOS不工作滚动溢出:隐藏

下一篇: Javascript和iPad touch event.identifier不断增加