我有3个街区(div)。当在那些块中单击时,div被选中并且它可以被类看到。
我需要禁用该元素的draggable(),因为即使在拖动功能中停止也是如此。 JS:
$('#llens').on("click", "#mou", function (event) {
$(this).parents(':eq(2)').draggable({
disabled: false,
containment: "parent",
scroll: false,
cursor: "move",
delay: 200,
start: function (e, ui) {
remember = $(this).html();
$(this).addClass('fantasma');
},
stop: function (e, ui) {
$(this).removeClass('fantasma');
// **WHEN IS STOPPED IT MAY DISABLE THE DRAG**
}
<div id="llens">
<div class="bloc professor" id="bloc_profes" style="top:40px; left:200px; width:800px; height:200px " data-actiu="true"></div>
<div class="bloc text" id="bloc_text" style="top:100px; left:200px; width:800px; height:100px " data-actiu="false"></div>
<div class="bloc alumne" id="bloc_alumnes" style="top:200px; left:200px; width:800px; height:200px " data-actiu="false"></div>
</div>
答案 0 :(得分:1)
使用内置的destroy
方法,如下所示:
stop: function (e, ui) {
$(this).removeClass('fantasma').draggable('destroy');
}
文档页面位于:http://api.jqueryui.com/draggable/#method-destroy
完全删除可拖动功能。这将返回 元素回到pre-init状态。
答案 1 :(得分:0)
尝试更改可拖动元素的类,如:
removeClass("draggable").addClass("static");
您还可以添加以下支票:
if(hasClass("draggable"){
removeClass("draggable").addClass("static")}