3
我是用jQuery UI的可拖動的元素工作時,我遇到了一個問題將更大格。我想能夠拖動比容器大的div元素。於是,我就用位置:容器和位置上相對的:在拖曳的元素,絕對,但它不工作。基本上,我想做到的是這樣的:http://tech.pro/tutorial/790/javascript-tutorial-draggable-view-in-a-containerjQuery UI的可拖動:不是容器
您可以查看代碼的下面這裏的例子: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" });
});
感謝您的快速回復!我試過,但現在拖動對象(文本)其指定startPosition是容器外的方式..我想它來定位,所以你可以看到這樣的文字像(0,0)。我更新了鏈接,以便您明白我的意思! – Mikelo 2014-09-04 22:22:28
好吧,你爲什麼不只是設置初始CSS頂部和左側補償?我會更新我的答案。 – Greg 2014-09-04 22:38:36
啊,這真是愚蠢! TNX!解決了:) – Mikelo 2014-09-04 22:43:14