Jquery 在其父级中保留一个可拖动的div
我有一个可拖动的div标记,我希望它在被拖动时不要从其父级溢出Jquery 在其父级中保留一个可拖动的div,jquery,html,tags,position,limit,Jquery,Html,Tags,Position,Limit,我有一个可拖动的div标记,我希望它在被拖动时不要从其父级溢出 <script> $('.children').resizeable().draggable();//from jquerUI </script> <style> .parent{ overflow: hidden; position: relative; width: 1000px; height: 1000px;
<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>
$('.children').resizeable().draggable()//来自jquerUI
.家长{
溢出:隐藏;
位置:相对位置;
宽度:1000px;
高度:1000px;
}
.儿童{
宽度:100px;
高度:100px;
位置:绝对位置;
}
如何限制子元素在父元素中的位置和大小。下面是一个可拖动元素在另一个可拖动元素中的位置和大小
$('.children').draggable({ containment: "parent" });
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>jQuery UI Draggable - Default functionality</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.1/themes/base/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.1/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css" />
<style>
#draggable { width: 150px; height: 150px; padding: 0.5em; }
</style>
<script>
$(function() {
$( "#draggable" ).draggable();
$( "#draggable1" ).draggable({containment: "parent"});
});
</script>
</head>
<body>
<div id="draggable" class="ui-widget-content draggable">
<p>Drag me around</p>
<div id="draggable1" class="ui-widget-content draggable">
<p>Drag me around</p>
</div>
</div>
</body>
</html>
jQuery UI可拖动-默认功能
#可拖动{宽度:150px;高度:150px;填充:0.5em;}
$(函数(){
$(“#可拖动”).draggable();
$(“#draggable1”).draggable({containment:“parent”});
});
把我拖来拖去
把我拖来拖去
这不再有效。它是否回应了过时的东西?