Activate your free membership today | Log-in

Thursday, April 14th, 2005

Drag n’ Drop in JavaScript

Category: JavaScript

A lot of people ask about drag and drop, and here is a nice set of examples: Direct Manipulation Using JavaScript and CSS.

Direct manipulation, particularly drag and drop, is under utilized in desktop applications and is almost non-existant in web applications. The following examples demonstrate that direct manipulation is possible in modern browsers.

Each example is a proof of concept. I’m answering the question Can I do this? without considering the question Should I do this?. That said, some of these examples are pretty impressive, so it’s nice to think that sometimes the answer will be Yes, you should.

Examples

You can then combine these JavaScript functions with Ajax to make sure that the changes you made are persisted!

Posted by Dion Almaer at 8:29 am
13 Comments

+++--
3.5 rating from 25 votes

13 Comments »

Comments feed

http://www.dhtmlcentral.com/ for resize.

Comment by Bruno — April 14, 2005

Wow, those are some spectacular scripts!

Comment by ceejayoz — April 14, 2005

Cool stuff. One thing about the drag n drop lists. It seems like its all client side. How would this help in a real world situation where you need to store the new ordered lists that you just dragged and dropped? It doesn’t communicate with the server at anytime, so you can’t really save that information. Not sure how useful that would be.

I guess you can also set some hidden field values or use Ajax to communiate with the server. Now that would be a neat demo.

Comment by Ramin — April 14, 2005

What is the possibility of using nested UL lists with sorting? That is something that I would be very interested in.

Have you tried that at all?

Comment by David — April 14, 2005

Have you ever tried qooxdoo (qooxdoo.sourceforge.net). There is a full drag and drop implementation – but it’s target are web applications – not simple html pages.

Comment by Sebastian — April 15, 2005

I’m currently working on Drag&Drop for XHTML and SVG pages. In particular, I find your examples of sorting lists and slides very good (absolutely high drool factor). The code I wrote so far is able to handle mixed XHTML/SVG documents (compound documents). It can show a selection rectangle with resize handles, and it can be used to move and resize both XHTML and SVG elements, as long as they allow absolute positioning. The code hides differences in XHTML and SVG semantics.

However, currently one important thing for drag&drop is still missing: while it is now possible to handle the drag, it is not possible to detect whether a particular “thing” has been dropped onto a particular other element. Part of the problem is that there is no function to detect what is “under” the cursor and the object being dragged. I would like to see support for this coming from web browsers so writing cross-platform interactive web-applications could become a little more easier…

Comment by Harald Albrecht — April 18, 2005

ceejayoz,
you need to use Ajax for that … im using xajax (PHP) class for my apps – pretty easy to use and powerful

Comment by Romka — October 27, 2005

ceejayoz – Cool stuff. One thing about the drag n drop lists. It seems like its all client side. How would this help in a real world situation where you need to store the new ordered lists that you just dragged and dropped?

This IS client-side only. I would save things onunload. It would be possible to save ondragend, but that would require more trips to the server. On the other hand, in a failed use case (browser crash) where a lot of change was made onunload would lose ALL of the changes where as ondragend, only the last change would be lost.

Ramin – What is the possibility of using nested UL lists with sorting?

Definitely possible. Not much added difficulty, either.

You’ll find cooler examples on http://script.aculo.us/ and demos on my own site, too: http://dhtmlkitchen.com/scripts/draglib/demo/

These two scripts have droptargets, animation when dragging is canceled (animation back). Mine also has some keyboard accessibility features to select/deselect multiple objects (so you can drag a few things at a time) and ESC to cancel dragging. Demo: http://dhtmlkitchen.com/scripts/draglib/DragModule/demo/droptarget/

(The PNG doesn’t work in IE6 and I have no intention of using MS’s DXImageTransform “css” property. Let it work in IE7)

Comment by Garrett Smith — December 24, 2005

Ramin – What is the possibility of using nested UL lists with sorting?

I got it to work here ->
http://dhtmlkitchen.com/scripts/draglib/DragModule/demo/dragpane/nested-list.html

Comment by Garrett Smith — December 31, 2005

links of london
links oflondon charms
links oflondon necklaces
discount links of london
links oflondon bracelets
links oflondon bangles
links of london sale
links oflondon earrings
links oflondon rings
links of london jewellery
CharmBracelet
SweetieBracelet
links oflondon sweetie bracelet

Comment by linkssara — January 30, 2010

I’m currently working on Drag&Drop for XHTML and SVG pages. In particular, I find your examples of sorting lists and slides very good (absolutely high drool factor). The code I wrote so far is able to handle mixed XHTML/SVG documents (compound documents). It can show a selection rectangle with resize handles, and it can be used to move and resize both XHTML and SVG elements, as long as they allow absolute positioning. The code hides differences in XHTML and SVG semantics.
tiffany jewellery
tiffany jewelry
tiffany uk
links of london
sweetie bracelet
sweetie bracelets
charm bracelets
charm bracelet

Comment by lilith1976 — February 24, 2010

Each section of links of london jewelry has its own story.Sweetie bracelet,best for your beloved.Charm bracelet,perfect for Gold charms.Which do you like,sweetie bracelets or charm bracelets?

Comment by alwilda1975 — March 1, 2010

christian
louboutin

christian
louboutin shoes

christian
shoes

louboutin
shoes

christian
louboutin sale

christian
louboutin discount

christian
louboutin sale

Christian Louboutin Boots

Christian Louboutin Pumps  

Christian Louboutin Shoes

Christian Louboutin Sandals

Comment by christianlou — March 8, 2010

Leave a comment

You must be logged in to post a comment.