JQuery 可拖动元素不移动

JQuery draggable element not moving

我有一个简单的可拖动示例,它不起作用。当我尝试用鼠标移动时,可拖动元素(div 带有绿色边框)没有移动。

我的拖动代码:

  $("#divDraggable").draggable({
    revert: 'invalid',
    helper: 'clone'

  });

我只想将元素复制到另一个(更大的)元素中。如果它没有被丢弃,return 它到它的初始位置。为什么它不起作用?

$(function(){
  
  $("#divDraggable").draggable({
    revert: 'invalid',
    helper: 'clone'
    
  });



  
  
  $("#divDroppable").droppable({
    accept: '.draggable',
    drop: function (event, ui) {
        debugger;
        var droppable = $(this);
        var draggable = ui.draggable;
        draggable.clone().appendTo(droppable);        
    }
    
    
  });

  
  
})
#divDroppable{
  border:1px solid black;
  width: 300px;
  height: 300px;
}

#divDraggable{
  margin-top: 50px;
  width: 100px;
  height: 100px;
  border: 2px solid green;
}
<script src="https://test73.webo.hosting/Scripts/jquery-1.11.0.min.js"></script>
<script src="https://test73.webo.hosting/Scripts/jquery-ui-1.10.4.custom.js"></script>
<link href="https://test73.webo.hosting/Styles/jquery-ui-1.10.0.custom.css" rel="stylesheet"/>


<div id="divDroppable" class="draggable"></div>
<div id="divDraggable"></div>

您的 helper 属性在可拖动中的问题。请检查这个 fiddle,我删除了助手 属性 及其工作 https://jsfiddle.net/x6hdan8L/1/

语法错误。应该是这样的:

$("#divDraggable").draggable({
    revert: true,
    helper: 'clone'

  });

工作示例:

draggable

给你一个解决方案https://jsfiddle.net/4hzcq0q5/

$(function(){
  
  $("#divDraggable").draggable({
    revert: 'invalid',
    helper: 'clone',
  });
  
  $("#divDroppable").droppable({
    accept: '.draggable',
    drop: function (event, ui) {
        var droppable = $(this);
        var draggable = ui.draggable;
        draggable.clone().appendTo(droppable);        
    }   
  });  
})
#divDroppable{
  border:1px solid black;
  width: 300px;
  height: 300px;
}

#divDraggable{
  margin-top: 50px;
  width: 100px;
  height: 100px;
  border: 2px solid green;
}
<link href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" rel="stylesheet"/>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<div id="divDroppable" ></div>
<div id="divDraggable" class="draggable">

</div>

问题出在你身上 class class="draggable" 添加到 已删除 div 而不是 可拖动 div .