[英]Containing a draggable div to parent
I am working with jquery ui draggable library. 我正在使用jQuery ui可拖动库。 On a button on click I am able to create and append text to a new div.
在单击的按钮上,我能够创建文本并将其附加到新的div。 But I am running into two problems: the created new divs do not stay contained to the parent div.
但是我遇到了两个问题:创建的新div不会包含在父div中。 In other words How can I keep the draggable divs inside parent div
container
? 换句话说,如何将可拖动的div保留在父div
container
? Second I have set a z-index
in order to be able to overlap one div in top of another. 其次,我设置了一个
z-index
,以便能够将一个div与另一个div重叠。 Currently the latest created div stays on top. 当前,最新创建的div位于最上方。 How can a make divs overlappable not depending on the element creation order?
不取决于元素创建顺序,make div如何可重叠? JSFIDDLE
的jsfiddle
Jquery jQuery的
var z = 1; //value to make div overlappable
$('#addText').click(function (e) {
/** Make div draggable **/
$('<div />', {
class: 'ui-widget-content',
appendTo: '.container',
draggable: {
containment: 'parent',
start: function( event, ui ) {
$(this).css('z-index', ++z);
}
}
});
});
HTML HTML
<div class="container">
<div data-bind="foreach:items" class="fix_backround">
<div href="#" class="item" data-bind="draggable:true,droppable:true">
<span data-bind="click:$parent.remove">[x]</span><br/><br/>
<center><span class="text" data-bind="text:$data"></span><input class="edit_text"/></center>
</div>
</div>
For your first problem, use position
and overflow
properties for your .container
element: 对于第一个问题,请对
.container
元素使用position
和overflow
属性:
.container {
position: relative;
overflow: auto;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.