How can I get jQuery UI's Draggable and Sortab

2020-02-16 20:16发布

问题:

I have a page that uses JQuery UI; in particular the Sortable interaction.

The page works fine for desktop web browsers with mice, however I can't get the drag-drop functionality to work on Mobile Safari on the iPhone. Any dragging action simply scrolls the page.

The functionality on my page is extremely similar to the Sortable Empty-Lists demo on the JQuery UI site. This page also doesn't work on the iPhone.

Is there any way to get the drag-drop functions working on the iPhone?

回答1:

According to the Mobile Safari docs drag and drop is not supported, but it can be simulated. Since basically dragging your finger along will scroll the browser you will have to disable this. That can be done like this:

$(document).bind('touchmove', function(e) {
   e.preventDefault();
}, false);

Otherwise the event you will have to handle are touchstart, touchmove and touchend.



回答2:

This is a demo of jquery ui 1.9pre: https://dl.dropbox.com/u/3872624/lab/touch/index.html

The jquery.mouse.ui.js file is working great for me.