Javascript n“滚动”滚动条。但你知道为什么要这样做,因为手机上的一个页面已经有了滚动条。不明白你想用它做什么。成功我必须添加列的拖放和滚动。当我在chrome中打开touch事件时,我无法滚动表格。甚至在手机上都没有。你在Windows Phone上测试过吗?或者除
Javascript n“滚动”滚动条。但你知道为什么要这样做,因为手机上的一个页面已经有了滚动条。不明白你想用它做什么。成功我必须添加列的拖放和滚动。当我在chrome中打开touch事件时,我无法滚动表格。甚至在手机上都没有。你在Windows Phone上测试过吗?或者除,javascript,jquery,jquery-ui,touch,Javascript,Jquery,Jquery Ui,Touch,n“滚动”滚动条。但你知道为什么要这样做,因为手机上的一个页面已经有了滚动条。不明白你想用它做什么。成功我必须添加列的拖放和滚动。当我在chrome中打开touch事件时,我无法滚动表格。甚至在手机上都没有。你在Windows Phone上测试过吗?或者除了iPhone以外的其他东西?从过去的经验来看,这似乎在iPhone/iPad上工作得很好,但在其他设备上,特别是在Windows手机上,效果并不理想。 function touchHandler(event) { var touch
n“滚动”滚动条。但你知道为什么要这样做,因为手机上的一个页面已经有了滚动条。不明白你想用它做什么。成功我必须添加列的拖放和滚动。当我在
chrome
中打开touch
事件时,我无法滚动表格。甚至在手机上都没有。你在Windows Phone上测试过吗?或者除了iPhone以外的其他东西?从过去的经验来看,这似乎在iPhone/iPad上工作得很好,但在其他设备上,特别是在Windows手机上,效果并不理想。
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);
}
if (event.target.id == 'draggable_item' ) {
event.preventDefault();
}
var $target = $(event.target);
if( $target.hasClass('draggable') ) {
event.preventDefault();
}
var clickms = 100;
var lastTouchDown = -1;
var d = new Date();
switch(event.type)
{
case "touchstart": type = "mousedown"; lastTouchDown = d.getTime(); break;
case "touchmove": type="mousemove"; lastTouchDown = -1; break;
case "touchend": if(lastTouchDown > -1 && (d.getTime() - lastTouchDown) < clickms){lastTouchDown = -1; type="click"; break;} type="mouseup"; break;
default: return;
}
simulateTouchEvents(<object>);
simulateTouchEvents(<object>, true); // ignore events on childs
function simulateTouchEvents(oo,bIgnoreChilds)
{
if( !$(oo)[0] )
{ return false; }
if( !window.__touchTypes )
{
window.__touchTypes = {touchstart:'mousedown',touchmove:'mousemove',touchend:'mouseup'};
window.__touchInputs = {INPUT:1,TEXTAREA:1,SELECT:1,OPTION:1,'input':1,'textarea':1,'select':1,'option':1};
}
$(oo).bind('touchstart touchmove touchend', function(ev)
{
var bSame = (ev.target == this);
if( bIgnoreChilds && !bSame )
{ return; }
var b = (!bSame && ev.target.__ajqmeclk), // Get if object is already tested or input type
e = ev.originalEvent;
if( b === true || !e.touches || e.touches.length > 1 || !window.__touchTypes[e.type] )
{ return; } //allow multi-touch gestures to work
var oEv = ( !bSame && typeof b != 'boolean')?$(ev.target).data('events'):false,
b = (!bSame)?(ev.target.__ajqmeclk = oEv?(oEv['click'] || oEv['mousedown'] || oEv['mouseup'] || oEv['mousemove']):false ):false;
if( b || window.__touchInputs[ev.target.tagName] )
{ return; } //allow default clicks to work (and on inputs)
// https://developer.mozilla.org/en/DOM/event.initMouseEvent for API
var touch = e.changedTouches[0], newEvent = document.createEvent("MouseEvent");
newEvent.initMouseEvent(window.__touchTypes[e.type], true, true, window, 1,
touch.screenX, touch.screenY,
touch.clientX, touch.clientY, false,
false, false, false, 0, null);
touch.target.dispatchEvent(newEvent);
e.preventDefault();
ev.stopImmediatePropagation();
ev.stopPropagation();
ev.preventDefault();
});
return true;
};