I’m trying to have two 2 separate Divs resizable, draggable and in the SAME containment Div.
This is what I have tried.
$(".main .box1").draggable({ containment: ".main" }).resizable({ containment: ".main" });
$(".main .box2").draggable({ containment: ".main" }).resizable({ containment: ".main" });
body {
background-color: #6A6A6A;
overflow: hidden;
}
html,
body {
height: 100%;
}
.box {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
.main {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
.box1 {
position: absolute;
top: 100px;
left: 100px;
width: 100px;
height: 100px;
background-color: black;
}
.box2 {
position: absolute;
top: 100px;
right: 100px;
width: 100px;
height: 100px;
background-color: black;
}
<div class="main">
<div class="box1"></div>
<div class="box2"></div>
</div>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.14.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-3.7.1.js"></script>
<script src="https://code.jquery.com/ui/1.14.1/jquery-ui.js"></script>
This only works on 1 Div. The other just disappears. In other ways, I tried the divs were always in sync.
So my question is How do you Have multiple Divs with the same Containment box?
2
Answers
Try this CSS and use each instead
Try this solution: