【问题标题】:jQuery draggable DIV with icon带有图标的 jQuery 可拖动 DIV
【发布时间】:2015-08-26 09:25:05
【问题描述】:

我想用 jQuery' 使一些可拖动的 DIV 可拖动,但它们本身不应该是可拖动的,但只能在每个 DIV 顶部的一个小图标的帮助下,这样我只能移动它,如果我点击并将该图标拖动到 DIV 上方,而不是在我单击并拖动 div 时拖动。

提前致谢

【问题讨论】:

    标签: jquery jquery-ui draggable


    【解决方案1】:

    使用句柄:

    $( "#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>

    【讨论】:

      猜你喜欢
      • 2012-06-09
      • 2010-10-12
      • 2012-01-24
      • 1970-01-01
      • 2011-12-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-28
      相关资源
      最近更新 更多