To make an object draggable set draggable=true on that element. Just about anything can be drag-enabled: images, files, links, files, or any markup on your page. Our example creates an interface to rearrange columns that have been laid out with CSS Grid.
Draggable() Method This method allows the elements to be dragged with the help of mouse. Using jQuery UI, we can make the DOM(Document Object Model) elements to drag anywhere within the view port. This can be done by clicking on the draggable object by mouse and dragging it anywhere within the view port.
After wasting many hours, I came across this!
jquery-ui-touch-punch
It translates tap events as click events. Remember to load the script after jquery.
I got this working on the iPad and iPhone
$('#movable').draggable({containment: "parent"});
Caution: This answer was written in 2010 and technology moves fast. For a more recent solution, see @ctrl-alt-dileep's answer below.
Depending on your needs, you may wish to try the jQuery touch plugin; you can try an example here. It works fine to drag on my iPhone, whereas jQuery UI Draggable doesn't.
Alternatively, you can try this plugin, though that might require you to actually write your own draggable function.
As a sidenote: Believe it or not, we're hearing increasing buzz about how touch devices such as the iPad and iPhone is causing problems both for websites using :hover/onmouseover functions and draggable content.
If you're interested in the underlying solution for this, it's to use three new JavaScript events; ontouchstart, ontouchmove and ontouchend. Apple actually has written an article about their use, which you can find here. A simplified example can be found here. These events are used in both of the plugins I linked to.
This project should be helpful - maps touch events to click events in a way that allows jQuery UI to work on iPad and iPhone without any changes. Just add the JS to any existing project.
http://code.google.com/p/jquery-ui-for-ipad-and-iphone/
jQuery ui 1.9 is going to take care of this for you. Heres a demo of the pre:
https://dl.dropbox.com/u/3872624/lab/touch/index.html
Just grab the jquery.mouse.ui.js out, stick it under the jQuery ui file you're loading, and that's all you should have to do! Works for sortable as well.
This code is working great for me, but if your getting errors, an updated version of jquery.mouse.ui.js can be found here:
Jquery-ui sortable doesn't work on touch devices based on Android or IOS
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With