【发布时间】:2016-03-15 06:53:53
【问题描述】:
http://jsbin.com/xidoruheti/edit?html,css,js,output
根据api:http://api.jqueryui.com/draggable/#option-helper
我不知道为什么在我指定 helper: 'clone' 后 div 变得不可拖动
【问题讨论】:
标签: jquery jquery-ui jquery-ui-draggable
http://jsbin.com/xidoruheti/edit?html,css,js,output
根据api:http://api.jqueryui.com/draggable/#option-helper
我不知道为什么在我指定 helper: 'clone' 后 div 变得不可拖动
【问题讨论】:
标签: jquery jquery-ui jquery-ui-draggable
试试这个。实际上拖动是有效的,但是你看不到元素。因为你为#id指定了样式,但是在使用克隆选项拖动时,插件将删除 id 属性。所以你看不到被拖动的元素。
$("#toDrag").draggable({
helper: "clone"
});
$("#toDragId").draggable({
helper: "clone",
start: function(e, u) {
$(u.helper).attr("id", "toDragId");
}
});
.clone,
#toDragId {
width: 100px;
height: 100px;
background: blue;
}
#toDragId {
width: 100px;
height: 100px;
background: green;
}
<link href="https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css" rel="stylesheet" type="text/css" />
<script src="https://code.jquery.com/jquery-1.11.3.js"></script>
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<div id="toDrag" class="clone"></div>
<br>
<div id="toDragId"></div>
【讨论】:
id属性。所以为了使它工作,你可以在start事件中添加id属性来克隆