4 ms·
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 wa
by jvickers 12y ago
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.
- striking 12y agoDo 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.
- jvickers 12y agoIf 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.