I am dynamically generating some divs inside a container and these are draggable using the latest version of jquery-ui. The problem is when a div moves to another position, it does not respect the space of the other divs, so it can be on top of another div and I do not want that.
this is what happens if I decide to move a div and put it on over another div:
This behavior is not good, the best would be that if I try to put one div on another, this action will not be executed.
This is my html code:
<div class="container">
<div class="row" id="main_row_blog_results">
<!--here the divs are dynamically generated -->
</div>
</div>
This is my JS code:
$(document).ready(function(){
$("#btnAddTextsBlog").click(function(){
var texts = "this is a random text";
var content2 = "<div id='text1' class='draggable' style='float: left; margin-left: 30px; margin-right: 30px; margin-top: 30px; display: block;'><p contenteditable='true' style='font-size: 18px;'>"+texts+"</p></div>";
$("#main_row_blog_results").append(content2);
$(".draggable").draggable();
});
$( '.draggable' ).draggable({
});
I would like to know how I could do to When user drags the div and drop it into the space of other div, move this div back to its original position...The idea is prevent collision between divs?