簡體   English   中英

拖放到放置jQuery的位置

[英]Drag and Drop in position dropped jquery

我在jqxtree中繪制了一棵樹。 我必須拖動樹元素並繪制一個小框div並追加到div id processFlowId

dragAndDrop代碼

$( ".dragItem" ).draggable({ revert: true,
         revertDuration: 0,
         cancel : 'span',
         refreshPositions: true 
        //,containment: "parent"
         ,helper: 'clone'});
$('#jqxTree').jqxTree({
       height: '200px',
       width: '300px',
       theme: 'energyblue',
       allowDrag: true,
       allowDrop: false
   });
 $(".dragItem").css({"position": ""});
var itemFlag =0;
$("#acceptDrop").droppable({
          accept: ".dragItem",
          activeClass: "drop-active",
          hoverClass: "drop-hover",
          drop: function (event, ui) {
              var itemid = ui.draggable.attr("id");
              itemFlag++
              drawAttrList(itemid + "_" + itemFlag,itemid,"processElement",ui);
          }
});
function drawAttrList(mainDivId, droppedToolId, dataMiningType,ui) {
    var html = '<div class="mouseHover" id="'+ mainDivId+ '"'
     + 'style="width:200px;"'+'><div class="widget-box w"><div class="widget-header" title="'+ mainDivId+ '">';
html += '<h4 class="lighter smaller" onclick="openProperties(\''
            + mainDivId + '\',\'' + dataMiningType
            + '\')"><i class="icon-random blue"></i>' + droppedToolId + '</h4>';
    html += '</div>';

    html += '<div  class="widget-body" ><div class="widget-main" ><div class="row-fluid">';

    html += '<div id="cart_toolbarList " class="drags"><div id="'+itemFlag+ droppedToolId + 'List_items" style="height:100px">';
    html += '<ul  class="item-list ui-sortable ' + droppedToolId + 'List'+ itemFlag + '" style="height:100%;border-style: dashed;border-width: 1px;border-color: silver;">';
    html += '</ul></div></div></div></div></div></div></div>';
    $("#" + mainDivId).draggable({
        revertDuration : 0,
        refreshPositions : true,
        revert: true,
        helper : 'clone'
    });
    $("#processFlowId").append(html);
}

請參考我的Jsfiddle

問題

我需要拖動li並相應地在放下的位置繪制。 現在,它不在我們放置的位置繪制。

任何建議做到這一點! 提前致謝!

要獲得放置位置,我們使用ui.position,它將相對於offset元素給出“頂部,左側”。

var top = ui.position.top; // gives the top postion
var left = ui.position.left; // gives the left postion

現在,借助style屬性,將這些x和y坐標附加到小框div中,該小框div附加到div id“ processFlowId”中。 如,

<div class="mouseHover" id="'+ mainDivId+ '"'+ 'style="width:200px;position:absolute; top: '+ top+ 'px; left: '+ left+ 'px;"'>

查看更新的小提琴

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM