【发布时间】:2014-09-04 22:06:29
【问题描述】:
当我遇到问题时,我正在使用 jQuery UI Draggable 元素。我希望能够拖动比容器大的 div 元素。所以我尝试在容器上使用 position:relative 并在可拖动元素上使用 position:absolute 但它不起作用。基本上我想要完成的是:http://tech.pro/tutorial/790/javascript-tutorial-draggable-view-in-a-container
您可以在此处查看以下代码示例:http://bit.ly/1qhVxqJ
我的代码:
外部
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.1/jquery-ui.js"></script>
CSS
.draggable {
width: 750px;
height: 750px;
padding: 0.5em;
float: left;
position: absolute;
background: #6C6;
border:2px solid #fff;
}
#containment-wrapper {
height:500px;
width:700px;
background: #000;
margin-top:250px;
margin-left:500px;
border:2px solid #ccc;
position:relative;
overflow:hidden;
}
HTML
<div id="containment-wrapper">
<div id="draggable3" class="draggable ui-widget-content">
<p>I'm contained within the box</p>
</div>
</div>
jQuery
$(function() {
$( "#draggable3" ).draggable({ cursor: "move", containment: "#containment-wrapper" });
});
【问题讨论】:
标签: javascript jquery html css jquery-ui