Activate your free membership today | Log-in

Friday, July 17th, 2009

HTML5 Drag and Drop in deeetail

Category: Browsers, HTML

Les Orchard isn't just a cool domain name. He is a person. A person who has done a great job detailing HTML 5 drag and drop that you can use today in Firefox 3.5.

Les takes us down the path from simple drag and drop, to event propagation, to feedback images, to rich data transfer information all with great demos:

It is so cool to be able to do things like this:

JAVASCRIPT:
  1.  
  2. var dt = ev.originalEvent.dataTransfer;   
  3.  
  4. dt.setDragImage( $('#feedback_image h2')[0], 0, 0);
  5.  
  6. dt.setDragImage( $('#logo')[0], 32, 32);
  7.  
  8. var canvas = document.createElement("canvas");
  9. canvas.width = canvas.height = 50;
  10.  
  11. var ctx = canvas.getContext("2d");
  12. ctx.lineWidth = 8;
  13. ctx.moveTo(25,0);
  14. ctx.lineTo(50, 50);
  15. ctx.lineTo(0, 50);
  16. ctx.lineTo(25, 0);
  17. ctx.stroke();
  18.  
  19. dt.setDragImage(canvas, 25, 25);
  20.  

Drag and drop on the Web has always been a strange beast, but at least now we have a rich API.... so maybe it will get a revival?

Posted by Dion Almaer at 7:26 am
10 Comments

++++-
4.6 rating from 29 votes

10 Comments »

Comments feed TrackBack URI

Some of the demos also work in Webkit nightlies. Really cool.

Comment by devongovett — July 17, 2009

Finally something in HTML5 that is actually useful and has a chance of being implemented by Microsoft.

Comment by Darkimmortal — July 17, 2009

@Darkimmortal : System Drag&Drop has been introduced in 2000 in IE 5.0. My two cents…

See

Comment by SleepyCod — July 17, 2009

We have also implementation of this Drag&Drop API (initially created by MS, as noted by SleepyDog) with minor limitations in Ample SDK http://www.amplesdk.com/examples/extensions/ Works in all browsers.

Comment by SergeyIlinsky — July 17, 2009

This also works in Safari Webkit nightlies. Not sure if it works in straight 4.0.2.

Comment by spullara — July 17, 2009

Webkit nightlies supports the draggable attribute, but Safari 4.x doesn’t just yet. Oddly you need to kick it with CSS using -khtml-user-drag: element;

I wrote an article for html5doctors.com last week or so ago going through DnD and cross browser issues to watch out for: native HTML 5 drag and drop.

Comment by remy — July 18, 2009

I don’t get it. Why does WHAT-WG prefer to solve problems which already have solutions?

Drag’n'drop is very easy to implement if you use Flapjax for example.

Comment by chiaroscuro — July 19, 2009

Interesting to know that CSS may be formatted in so many styles. It was interesting to me.

Comment by stoimen — July 20, 2009

Thanks for that
We are leraning

Comment by RawChocolate — July 30, 2009

With the changing trend of the world, wedding apart from white,Princess Strapless Satin Evening Dress ivory, beige and other traditional colors,are also increasingly popular in recent years, ghetto prom dressespink wedding package,gothic prom dresses such as pink, pink orange, baby blue, purple night, light green and light silver-gray, very soft and pleasing to wedding hair accessoriesthe eye; if you have the courage to try, dark green, purplish red, deep purple, decorated in pink wedding dress, the formation of rich colors,the dress, the effect is very special;Sash Lace Satin Flower Girl Dress, laden with flour colored silk flowers, butterflies, in order to add color.wedding dressIn fact, the wedding is the color of lesser importance, the most important prerequisite is to match the bride’s complexion. Oriental deep and yellowish color, wearing white Mermaid Satin Organdie Wedding Dress,will appear dull, wearing ivory would be more harmonious and natural, baby blue, wedding accessoriespurple night can not be coordinated with the yellow, but pink orange, light green with yellowish color match. As for the skin and rosy, or bronze skin, wearing white will look great, wedding dress

Comment by wuwei — November 10, 2009

Leave a comment

You must be logged in to post a comment.