Ale*_*rov 26 iphone android jquery-ui jquery-ui-sortable ios
是否有任何解决办法使Jquery-ui可以在基于Android或IOS的触摸设备上进行排序?
bal*_*and 33
我建议使用jQuery UI Touch Punch.我已经在iOS 5和Android 2.3上测试了它,它在两者上都很好用.
小智 26
另一个答案很棒但不幸的是它只适用于iOS设备.
此外,jquery.ui的更高版本导致了破坏,这意味着_touchEnd事件未正确重置mouse.ui中的内部标志(mouseHandled),这导致异常.
现在应该使用此代码修复这两个问题.
/*
* Content-Type:text/javascript
*
* A bridge between iPad and iPhone touch events and jquery draggable,
* sortable etc. mouse interactions.
* @author Oleg Slobodskoi
*
* modified by John Hardy to use with any touch device
* fixed breakage caused by jquery.ui so that mouseHandled internal flag is reset
* before each touchStart event
*
*/
(function( $ ) {
$.support.touch = typeof Touch === 'object';
if (!$.support.touch) {
return;
}
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 );
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
23948 次 |
最近记录: |