我正在使用这样的代码来使其响应jQuery UI滑块&在ipad / iphone上拖放html网页(并且运行良好)的东西。
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;
}
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 initTouch()
{
document.addEventListener("touchstart", touchHandler, true);
document.addEventListener("touchmove", touchHandler, true);
document.addEventListener("touchend", touchHandler, true);
document.addEventListener("touchcancel", touchHandler, true);
}
$(document).ready(function (){initTouch();});
拖动和滑动效果很好。 问题是当我想在html按钮(如“输入”或“a”)上进行简单的点击(点击)时,无法正常工作。
我认为它类似于“它理解这种轻拍就像第一次移动”。 我怎么做,当我在同一个地方轻轻点击(没有移动或拖动)时,让它也可以。或者,如果我触摸HTML的特定元素。
非常感谢, 梅西
答案 0 :(得分:2)
我也面临同样的问题。但是能够通过更改touch.js文件来解决这个问题: “if($(this).attr('href')=='')”在event.preventDefault();
之前