I am trying to create a page with div modules which contain various content. These should be able to be dragged by the user and dropped into a new position but I want them to snap into position below or above the other div module where they are dropped. An example of this can be seen on the BBC homepage (http://www.bbc.co.uk).
I have created my basic layout which is a div container with 3 children: left, center, and right. These children will be my columns. Each of the columns have div modules as children but I will want the user to be able to move a div module from one column to another.
As I understand I will be using 3 events for the drag drop facility. One is when the user clicks on a div module (onMouseDown), another is when the user moves the mouse (onMouseMove), and finally when the user releases the mouse button (OnMouseUp). However, I am unsure of how to approach this and particularly how to get the div module to detect where it should snap into place.
My layout html is shown below (very basic due the development and testing):
Thanks Fang for that link. I had a look and the problem with that code is that is is for an unordered list and when the code is adapted for a div it looks for the immediate parent as a container although in my layout there are 2 other containers (left, center, right) depending on the current container. Do you have any more suggestions?
Additionally, I want the theory for snapping the div into place so that I can code this from scratch. The main thing I cannot understand is how the div being dragged knows where it should snap into.