Hello, I have a div with some text that depending on the size of the browser window is 50% form the left. I'd like to be able to let people drag it to the side if they wish. Does anyone know how I could do this? Thanks

1 answer

danwellman 5600
2
points
This was chosen as the best answer

You can use jQuery UI to make an element draggable. It's really easy, essentially, all you need to do to enable dragging is called the draggable method on the element, something like this:

$("#id_of_the_element").draggable();

If you have added jQuery and jQuery UI to the page correctly that will work. There are also a range of options you can set to control how the draggable interaction works. See the documentation page for more info

Answered almost 8 years ago by danwellman
  • could you do it with html5? Numbers McPi almost 8 years ago
  • Just HTML5? Sure: http://www.html5rocks.com/en/tutorials/dnd/basics/ but jQuery UI is better supported at present. IE (even v 9) doesn't support the native DnD API... danwellman almost 8 years ago
  • Many thanks! sbl2000 almost 8 years ago
  • Also, as pointed out on QuirksBlog, at least two years ago it is confusing. It looks like there are still 7 total events in the spec. http://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html Ktash almost 8 years ago
  • Though reading through the spec they seem to have cleaned up a few of the issues listed. Not sure if drag still require the two other events to be cancelled or not, can't find it. Ktash almost 8 years ago