我正在使用 phonegap 开发的 android 应用程序中使用 jquery-ui 实现拖放功能。一切正常。我用于jquery.ui.touch-punch.js
触摸事件。问题是我在 android 平板电脑中通过触摸拖动时没有得到帮助。助手在桌面浏览器中工作正常。
问问题
1471 次
2 回答
4
这是一个工作示例:http: //jsfiddle.net/Gajotres/rjC9q/
我已经在 Android 4.1.1 和 iPad 6.0 上对其进行了测试。
要使其工作,您还需要添加以下代码:
/iPad|iPhone|Android/.test( navigator.userAgent ) && (function( $ ) {
var proto = $.ui.mouse.prototype,
_mouseInit = proto._mouseInit;
$.extend( proto, {
_mouseInit: function() {
this.element
.bind( "touchstart." + this.widgetName, $.proxy( this, "_touchStart" ) );
_mouseInit.apply( this, arguments );
},
_touchStart: function( event ) {
/* if ( event.originalEvent.targetTouches.length != 1 ) {
return false;
} */
this.element
.bind( "touchmove." + this.widgetName, $.proxy( this, "_touchMove" ) )
.bind( "touchend." + this.widgetName, $.proxy( this, "_touchEnd" ) );
this._modifyEvent( event );
$( document ).trigger($.Event("mouseup")); //reset mouseHandled flag in ui.mouse
this._mouseDown( event );
//return false;
},
_touchMove: function( event ) {
this._modifyEvent( event );
this._mouseMove( event );
},
_touchEnd: function( event ) {
this.element
.unbind( "touchmove." + this.widgetName )
.unbind( "touchend." + this.widgetName );
this._mouseUp( event );
},
_modifyEvent: function( event ) {
event.which = 1;
var target = event.originalEvent.targetTouches[0];
event.pageX = target.clientX;
event.pageY = target.clientY;
}
});
})( jQuery );
我不是这段代码的作者,它是Oleg Slobodskoi。
于 2013-03-06T13:21:09.837 回答
0
于 2013-03-06T11:55:30.403 回答