【问题标题】:Why can't I drag the div after I specify helper: "clone"为什么我指定助手后不能拖动div:“克隆”
【发布时间】: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


    【解决方案1】:

    试试这个。实际上拖动是有效的,但是你看不到元素。因为你为#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 作为选择器来设置 div 元素的样式。但是怎么会呢?
    • 你可以使用,但是jquery可拖动插件在拖动时删除了克隆元素的id属性。所以为了使它工作,你可以在start事件中添加id属性来克隆
    猜你喜欢
    • 2023-04-02
    • 2014-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-22
    • 2011-08-28
    • 1970-01-01
    • 2011-07-15
    相关资源
    最近更新 更多