当我同时使用jquery-ui resizable
和draggable
时,我遇到了一个问题。以下是出现问题时的场景:
first move父分区,
然后,调整子分区的大小。
最终子分区显示不正确
如果我去掉了可调整大小的containment
选项,效果就没问题了。
我发现选项containment and
helper` `不能同时存在。
谢谢
这是演示
// 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>
发布于 2019-06-10 23:57:16
我会远离使用帮助器,我发现使用它们有很多问题。
在使用jquery-ui交互时,我在容器中使用了一个内部元素,这样小部件就不会受到容器中任何其他元素的影响。例如,由于"p1“元素,调整大小容器不能正常工作,为了避免这种情况,您可以像我一样添加一个内部元素,或者将任何其他内部元素设为position: absolute;
,这样它们就不会影响ui-element。
下面是我的例子:
$('.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>
https://stackoverflow.com/questions/47628931
复制相似问题