2013-07-03 52 views
0

表我beginer到js和jQuery和我需要一点点的帮助,如果有人能帮助我...将DIV从侧边栏与jQuery UI的

我要做些什么?

我想将div从侧栏拖到表格中。在侧边栏div必须只能拖动到表格。当我将div拖放到表格中时,表格中的div必须可以调整大小并再次拖动。

照片: enter image description here

我尝试用这个代码,但不工作得很好:

$(function() { 
    $(".draggable").resizable(); 
    $(".draggable").draggable({revert: 'invalid', helper:'clone', snap: "#drop_here td", opacity: 0.7}); 
    $("#drop_here td").droppable({ 
     accept: '.draggable', 
     drop: function(event, ui) { 
     $(this) 
      .find("p") 
      .html("Dropped!"); 
     } 
    }); 
    }); 

DEMO及源代码:http://jsbin.com/erofot/17/edit | http://jsbin.com/erofot/17

+1

我这么想吗?这不正是你的代码已经在做什么?还是我错了什么? – rusln

+0

是的,但我不能克隆元素,我拖动原始元素:) –

回答

0

这里是你如何能做到这一点,则:(更换你有jsbin使用此代码) jsbin

$(function() { 
    //$(".draggable").resizable(); 
    $(".draggable").draggable({ 
     revert: 'invalid', 
     helper:"clone", 
     snap: "#drop_here td", 
     opacity: 0.7 
    }); 
    $("#drop_here td").droppable({ 
     // accept only from left div, 
     // this is necessary to prevent clones duplicating inside droppable 
     accept: '#left .draggable', 
     drop: function(event, ui) { 
     // 4 append clone to droppable 
     $(this).append(
      // 1 clone draggable helper 
      $(ui.helper).clone() 
      // 2 make the clone draggable 
      .draggable({containment:"parent"}) 
      // 3 make the clone resizable 
      .resizable()); 
     } 
    }); 
    }); 
+0

我不知道为什么,但是当我将这段代码复制到我的原始代码(当实现这个我的应用程序时)div .draggable将不会追加在位置上我拖动他,Div附加在我的位置+ 50,70,100px等等或类似 –

+0

的东西,也请告诉我可克隆div如何可拖动到表中? –

+0

我用[jsbin](http://jsbin.com/erofot/105/edit) – rusln