你可以自己擴展庫,無需太多工作。
因爲如果設備支持觸摸還是不容易的檢查:
var supportTouch = ("ontouchend" in document);
然後你可以使用基於適當的情況下,如果觸摸啓用與否,下面是jQuery中移動圖書館使用:
var touchStartEvent = supportTouch ? "touchstart" : "mousedown",
touchStopEvent = supportTouch ? "touchend" : "mouseup",
touchMoveEvent = supportTouch ? "touchmove" : "mousemove";
然後更改使用這些變量而不是當前的硬編碼鼠標事件庫,可能看起來是這樣的:
$(".sortable").bind("mousedown", doSomething());
但應該是這樣的:
$(".sortable").bind(touchStartEvent, doSomething());
做一些測試,你做太多的工作之前,我沒有測試上面的代碼,而不是看着這個排序庫。
另一個需要注意的是,某些移動設備不支持在瀏覽器中拖動對象,我所知道的是Windows Phone 7(包含Mango和不包含Mango)。如果你想支持那些你應該建立一些「非拖放」解決方案。
我剛剛將事件名稱更改爲'v *',但此代碼看起來更好,謝謝! –