タッチイベントをマウスイベントに変換するには、次のスクリプトを使用しています。それはかなりうまくいくが、2つのタッチイベント(例えば、図のデータをパンする)の間に2番目のイベントはトリガーされない。次に、次のイベントがトリガーされ、次のイベントはトリガーされません。タッチイベントをマウスイベントに変換するのは毎回のみです
だからこれは私の関数であるので、この動作はそのようである理由here
function touchHandler(event)
{
var touches = event.changedTouches,
first = touches[0],
type = "";
switch(event.type)
{
case "touchstart": type = "mousedown"; break;
case "touchmove": type = "mousemove"; break;
case "touchend": type = "mouseup"; break;
default: return;
}
// initMouseEvent(type, canBubble, cancelable, view, clickCount,
// screenX, screenY, clientX, clientY, ctrlKey,
// altKey, shiftKey, metaKey, button, relatedTarget);
var simulatedEvent = document.createEvent("MouseEvent");
simulatedEvent.initMouseEvent(type, true, true, window, 1,
first.screenX, first.screenY,
first.clientX, first.clientY, false,
false, false, false, 0/*left*/, null);
first.target.dispatchEvent(simulatedEvent);
event.preventDefault();
}
function init()
{
document.addEventListener("touchstart", touchHandler, true);
document.addEventListener("touchmove", touchHandler, true);
document.addEventListener("touchend", touchHandler, true);
document.addEventListener("touchcancel", touchHandler, true);
}
誰もが知っている見つけますか?
更新: 'first.target'は最初に 'div.dragcover'であり、2回目には 'rect'、もう一度 'div.dragcover'などと試してみました。なぜこれがそうだと誰でも知っていますか?
touchcancelイベントをmouseeventに変換しているようではありません。それは意図的なのでしょうか? –
私はtouchcancelイベントが本当に必要ない&私はそれにバインドする必要がどのマウスイベント、任意のアイデアを知りませんか? – threxx