根据我对您的问题的了解,您已尝试将上面提供的代码与the code snippet provided by Ross Boucher on Posterous 结合起来。尝试将这两个 sn-ps 背靠背组合是行不通的,因为在禁用 touchmove 时,您还禁用了允许 mousemove 通过他的示例工作的 shim。
This question and its answers 为您的问题制定一个可行的解决方案。你应该试试这两个 sn-ps 看看它们是否能解决你的问题:
This snippet, 禁用旧的滚动行为:
elementYouWantToScroll.ontouchmove = function(e) {
e.stopPropagation();
};
或者这个,来自the same:
document.ontouchmove = function(e) {
var target = e.currentTarget;
while(target) {
if(checkIfElementShouldScroll(target))
return;
target = target.parentNode;
}
e.preventDefault();
};
然后,加入the code on Posterous:
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();
}
这应该为你做。如果没有,则其他内容无法与 Mobile Safari 一起使用。