jQuery 可拖动 DIV 带图标

jQuery draggable DIV with icon

我想制作一些可拖动的 DIV 和 jQuery' 可拖动的,但它们本身不应该是可拖动的,只能借助每个 DIV,这样我只能移动它,如果我单击并拖动该图标到 DIV 上方,而不是每次单击并拖动 div.

时拖动它

提前致谢

使用句柄:

$( "#draggable" ).draggable({
  handle: "p"
});

片段

$(function() {
  $( "#draggable" ).draggable({ handle: "p" });
  $( "#draggable2" ).draggable({ cancel: "p.ui-widget-header" });
  $( "div, p" ).disableSelection();
});
#draggable, #draggable2 { width: 100px; height: 100px; padding: 0.5em; float: left; margin: 0 10px 10px 0; }
#draggable p { cursor: move; }
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<link rel="stylesheet" href="https://jqueryui.com/resources/demos/style.css">
<div id="draggable" class="ui-widget-content">
  <p class="ui-widget-header">I can be dragged only by this handle</p>
</div>

<div id="draggable2" class="ui-widget-content">
  <p>You can drag me around&hellip;</p>
  <p class="ui-widget-header">&hellip;but you can't drag me by this handle.</p>
</div>