Hacker News new | past | comments | ask | show | jobs | submit login

Updated the title to reflect that, thanks. Really makes you wonder though; why hasn't HTML5 Drag and Drop been simplified yet? I personally have no idea what to do, besides adding JQuery.



I've done some drag and drop programming, but not using the HTML5 API. I may have read that article quite a few years ago, but another problem was that HTML5 was not considered ready for use all those years ago. Recently (well, within the past year or so) I have found clients' requirements have been far less strict in terms of supporting older browsers, so I have been making use of more HTML5 features. I still have not used HTML5 drag-and-drop.

The basics of drag-and-drop only take a few lines to implement, but it's important to do extensive testing to find the edge cases. I found (one year ago) there were problems with jQuery UI that stopped me from making full use of it. I wound up using it for the basic dragging - it would reliably tell me mouse move events, clicks, buttons, and the mouse position, but because the droppables system would miss some events I implemented the logic surrounding detecting where the item was being dragged. Basically, whenever the item got moved, a whole bunch of calculations would run to see what object it's positioned over or near, and it's position within whatever object it's over.

If you want to do drag-and-drop programming in the browser, I recommend you write some code that allows you to pick up a DIV and drop it elsewhere on the screen. It's not trivial to do the first time, but once you understand the patterns it becomes so much easier. The techniques are useful for other similar things, like creating resize handles.


Do you have any code samples I could look at for reference? I'm quite new to the whole HTML/CSS thing, and I work best learning by example.


If I did write a code sample and replied here, would you get to see it?

I don't think there is a way to send messages on Hacker News, and I don't yet know if you'll get alerted to replies to old posts.


It has been, lots of things have been added since 2009 to fix most of his problems.


I wasn't aware of this. Do you have any reading material I could look at (as I'm attempting to implement DnD in an app of my own right now)?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: