Sto cercando di ottenere il drag/drop di jQuery per funzionare correttamente con gli eventi touch di iPad. Ho trovato questo codice su internet:Gestione di eventi touch per iPad per draggable/droppable (undefined changedTouches)
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();
}
Sembra funzionare bene se io attribuisco il touchHandler al document
TouchStart/spostare/fine, ma poi non lo zoom nativo/scorrimento sul iPad è consentito, quindi sono cercando di collegare semplicemente questo handler ai draggables stessi.
Il problema che sto vedendo con questo è che event.changeTouches
è sempre indefinito per qualche motivo, come si può testimoniare in http://jsfiddle.net/myLj2/1/. Non riesco a trovare una ragione per cui un evento touch avrà sempre una proprietà non definita changeTouches
e, a causa di ciò, questo codice non funzionerà. qualche idea?
appena salvato la mia giornata! –