如果将其添加到 HTML 文件中,它应该可以工作:
<script>
function touchHandler(event) {
var touch = event.changedTouches[0];
var simulatedEvent = document.createEvent("MouseEvent");
simulatedEvent.initMouseEvent({
touchstart: "mousedown",
touchmove: "mousemove",
touchend: "mouseup"
}[event.type], true, true, window, 1,
touch.screenX, touch.screenY,
touch.clientX, touch.clientY, false,
false, false, false, 0, null);
touch.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);
}
// Call the init function when the document has finished loading.
$(document).ready(function(){
init();
});
</script>
这最初来自这里:用于触摸设备的 Javascript 拖放
我在通过控制台运行代码后通过在 Chrome 中模拟触摸事件对此进行了测试,它可以在您的示例站点上运行。