Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

jQuery - drag element inside DIV / or sortable element

jQuery - drag element inside DIV / or sortable element

Problem

I'm having a problem with dragging a div inside an other div Element.

HTML looks like this:

All elements are draggable and have the css style float:left;position:relative;. When I drag el1 to the place of el3 it will work, but of course it will overlap the element el3. The draggin jquery draggable is working fine but I want to insert div with id el1at the HTML code in this position.

That it will look like this:

My problem now is, that this is a grid. el1 has the width of '300' all other the width of '100'. Dragin el1 to the place of el3 should swap el2, el3 and el4 to the place of el1 and el1 to the place of el2, el3, el4.

To get this behaviour I think I'm needed to move the div HTML code after el4. But how to determine which element is the nearest?

------- UPDATED-------

I way trying to use sortable... see here http://jsfiddle.net/vwK5e/2/ But if you put the red box over number 3, the red box will be in the second line (correct) but number 4 should be next to number 3 cause of the empty space.

TIA frgtv10

Problem courtesy of: frgtv10

Solution

Refer to http://jqueryui.com/demos/sortable/#display-grid

I guess you want functionality like this.

Answer

A different kind of jquery sortable

Solution courtesy of: jaychapani

Discussion

View additional discussion.



This post first appeared on CSS3 Recipes - The Solution To All Your Style Problems, please read the originial post: here

Share the post

jQuery - drag element inside DIV / or sortable element

×

Subscribe to Css3 Recipes - The Solution To All Your Style Problems

Get updates delivered right to your inbox!

Thank you for your subscription

×