我有一些嵌套的可拖动元素。 这是我的示例。
我想要设置可拖动子元素的顶部限制,以使子元素永远不会重叠到父标题上方。
我将其包含在父级中,但无法设置顶部位置,以使其无法拖动到父标题处。
_________________________
|_Parent__________________| <------- Don't overlap the containing parent heading
| |
| ___________ |
| |_Child_____| |
| | | |
| | | |
| | | |
| |___________| |
|_________________________|
HTML:
<div id="wrapper">
<div id="Parent">
<h4 class="ui-widget-header">Parent</h4>
<div id="Child">
<h4 class="ui-widget-header">Child</h4>
</div>
</div>
</div>
CSS:
#wrapper {
width: 800px;
height: 800px;
background: Yellow;
}
#Parent {
width: 250px;
height: 250px;
background: grey;
top: 100px;
left: 100px;
}
#Child {
width: 100px;
height: 100px;
background: white;
top: 0px;
left: 50px;
}
脚本:
$(function () {
$('#Parent').draggable({
cursor: 'move',
containment: 'parent'
});
$("#Child").draggable({
cursor: 'move',
containment: 'parent'
});
});