Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to constrain movement when using HTML5 native drag and drop?

Tags:

Various JavaScript libraries, such as jQuery UI, offer drag-and-drop interactions where you can constrain the movement of the dragged element to a single axis, or within a particular area.

Is this sort of thing possible using the native HTML5 drag and drop API?

like image 856
callum Avatar asked Jan 31 '12 10:01

callum


People also ask

Is drag-and-drop possible using HTML5?

Now HTML 5 came up with a Drag and Drop (DnD) API that brings native DnD support to the browser making it much easier to code up. HTML 5 DnD is supported by all the major browsers like Chrome, Firefox 3.5 and Safari 4 etc.

When the input device mouse is moved while the object is being dragged which of the following event will get fired?

1. Which event is fired as the mouse is moving over an element when a drag is occurring? Explanation: The dragover event is fired as the mouse is moving over an element when a drag is occurring.


1 Answers

It's totally different! The jQuery UI drag and drop make element move (with top and left CSS properties) in the page.

The native HTML5 drag and drop API only allow you to move a "ghost" of the draggable element (of course, you can hide the original element while dragging the ghost).

The API come with a lot of event but no, you can't constrain mouse position so you can't constrain to a single axis (cause the ghost follow the mouse position, even if the mouse leave the page (but event may probably stop operate)).

like image 161
Jordan Avatar answered Oct 16 '22 12:10

Jordan