元素不在jsPlumb中拖动

时间:2013-04-18 20:58:18

标签: jquery jquery-ui jsplumb

使用jsPlumb我的拖放操作无法正常工作。我让左侧的div可拖动,但是当你试图拖动它们时,只有线条移动,而不是div。 这是我的代码:

<html>
<head>
<title>Plumb Test</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.23/jquery-ui.min.js"></script>
<script type="text/javascript" src="js/jquery.jsPlumb-1.3.16-all-min.js "></script>
<script type="text/javascript">
$(document).ready(function(){
    jsPlumb.draggable($(".left"));
    jsPlumb.connect({source:"div1", target:"div2",
        paintStyle:{lineWidth:15,strokeStyle:'rgb(243,230,18)'},
        endpointStyle:{fillStyle:'rgb(243,229,0)'}
    });
    jsPlumb.connect({
        source:'div3',
        target:'div4',
        paintStyle:{ lineWidth:10, strokeStyle:'rgba(0, 0, 200, 0.5)' },
        anchors:["RightMiddle", "LeftMiddle"],
        endpoint:[ "Rectangle", { width:10, height:8 } ]
    });     
    jsPlumb.connect({
        source:'div2',
        target:'div3',
        paintStyle:{lineWidth:8, strokeStyle:'rgb(189,11,11)'},
        anchors:["BottomCenter", "TopCenter"],
        endpoint:"Rectangle"
    });     
    $("#div1").css("background-color","blue");
});
</script>
<style>
#div1, #div4{background-color:red;width:150px;height:150px;}
#div2, #div3{background-color:green;width:150px;height:150px;}
.left{float:left;}
.right{float:right;}
</style>
</head>

<body>
    <div id="div1" class="left">This is a test</div>
    <div id="div2" class="right">This is a div</div>
    <div id="div3" class="left">This is a test</div>
    <div id="div4" class="right">This is a div</div>
</body>
<html>

1 个答案:

答案 0 :(得分:5)

要启用拖动Div,必须绝对定位。

 <style>
 #div1, #div4{background-color:red;width:150px;height:150px;position:absolute; }
 #div2, #div3{background-color:green;width:150px;height:150px; position:absolute;}
 </style>

更多信息查看jsplumbs doc。

Your working fiddle