我在使用jquery-ui resizable
和draggable
时遇到问题。下面提到的是出现问题的场景:
先移动父Div,
然后调整孩子Div的大小
最终儿童Div显示不正确
如果我删除了可调整大小的containment
选项,那么就可以了。
我发现选项containment and
帮助者无法共存。
谢谢
这是演示
// external js: draggabilly.pkgd.js
$('.father').draggable({
handle:'.p1'
}).resizable({
helper: "ui-resizable-helper",
containment: "parent"
});
$('.child').draggable({
handle:'.p2'
}).resizable({
helper: "ui-resizable-helper",
containment: "parent"
});

body { font-family: sans-serif; }
.draggable {
width: 300px;
height: 300px;
background: #F90;
border-radius: 10px;
}
.draggable.is-pointer-down {
background: #09F;
}
p{ background: #F00;}
.child {
width:100px;
height:100px;
}
.draggable.is-dragging { opacity: 0.7; }
.ui-resizable-helper{ border: 1px dotted #20a0ff; }

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<link href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" rel="stylesheet"/>
<link href="https://jqueryui.com/resources/demos/style.css" rel="stylesheet"/>
<div class="draggable ui-widget-content father ">
<p class ="p1">handle</p>
<div id="resizable" class="draggable ui-widget-content child">
<p class ="p2">handle</p>
1234345 6
</div>
</div>
&#13;
答案 0 :(得分:0)
我会远离使用助手,我发现使用它们时会遇到很多问题。
在使用jquery-ui交互时,我在容器中使用了一个内部元素,以使小部件不受容器中任何其他元素的影响。例如,由于“ p1”元素,您的调整大小限制无法正常工作,要避免这种情况,您可以通过添加内部元素来完成我所做的事情,或者制作任何其他内部元素position: absolute;
以使它们起作用不会影响用户界面元素。
这是我的示例:
$('.father').draggable({
handle: '.p1'
}).resizable({});
var containTo = $('.father-inner');
$('.child').draggable({
handle: '.p2',
containment: containTo
}).resizable({
containment: containTo
});
body {
font-family: sans-serif;
}
.father-inner {
position: absolute;
top: 40px;
left: 5px;
right: 5px;
bottom: 5px;
}
.draggable {
width: 300px;
height: 300px;
background: #eee;
border: 1px solid #ccc;
border-radius: 10px;
}
.draggable.is-pointer-down {
background: #09F;
}
p {
background: #F00;
}
.child {
min-width: 100px;
min-height: 100px;
height: 100px;
width: 100px;
}
.draggable.is-dragging {
opacity: 0.7;
}
.ui-resizable-helper {
border: 1px dotted #20a0ff;
}
.ui-resizable-se {
width: 20px;
height: 20px;
position: absolute;
bottom: 0;
right: 0;
cursor: se-resize;
background: #aaa;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<div class="draggable ui-widget-content father ">
<p class="p1">handle</p>
<div class="father-inner">
<div id="resizable" class="draggable ui-widget-content child">
<p class="p2">handle</p>
1234345 6
</div>
</div>
</div>