在其父级中保留一个可拖动的div

Trầ*_*inh 5 html tags jquery position limit

我有一个可拖动的div标签,我希望它在被拖动时不会从其父节点溢出.

<script>
    $('.children').resizeable().draggable();//from jquerUI
</script>

<style>
    .parent{
        overflow: hidden;
        position: relative;
        width: 1000px;
        height: 1000px;
    }
    .children{
        width: 100px;
        height: 100px;
        position: absolute;
    }
</style>

<div class="parent">
   <div class="children"><div>
</div>
Run Code Online (Sandbox Code Playgroud)

如何限制孩子在父母中的位置和大小.

Eug*_*e H 12

$('.children').draggable({ containment: "parent" });
Run Code Online (Sandbox Code Playgroud)