我正在开发一个比较网站,您可以使用jQuery UI的可排序功能水平对项目进行排序。所有项目都在一个容器内,可以水平或垂直滚动。 它在桌面上工作正常,我试图让它在平板电脑上运行。
我已经可以通过以下方式使可排序功能在平板电脑上运行:jsFiddle
document.addEventListener("touchstart", module.bindTouchHandler, true);
document.addEventListener("touchmove", module.bindTouchHandler, true);
document.addEventListener("touchend", module.bindTouchHandler, true);
document.addEventListener("touchcancel", module.bindTouchHandler, true);
module.bindTouchHandler = function(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();
}
问题是不同的触摸事件现在阻止了水平/垂直滚动的可能性。我想对此有所延误。就像只有用户触摸它2秒才开始排序/拖动元素。
我该如何处理?
答案 0 :(得分:0)
虽然我无法直接评论您的问题,但最近我遇到了在触摸设备上使用jQuery UI的类似问题。虽然jQuery的官方触摸支持即将出现(expected to show in version 1.14),但furf创建了一个优雅的黑客,允许触摸与jQuery UI一起工作,而不费力。请在此处查看:http://touchpunch.furf.com/