红颜莎娜
我确定这是您想要的: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); }我已经捕获了触摸事件,然后手动触发了自己的鼠标事件以进行匹配。尽管该代码并不是特别通用,但要适应大多数现有的拖放库,甚至可能是大多数现有的鼠标事件代码,都应该是微不足道的。希望这个想法对开发用于iPhone的Web应用程序的人有用。更新:在发布此内容时,我注意到调用preventDefault所有触摸事件将阻止链接正常工作。preventDefault根本不打电话的主要原因是停止手机滚动,您可以通过仅在touchmove回叫上拨打电话来做到这一点。这样做的唯一缺点是,iPhone有时会在拖动原点上方显示其悬停弹出窗口。如果我发现了一种防止这种情况的方法,我将更新这篇文章。第二次更新:我发现CSS属性可以关闭标注:-webkit-touch-callout。