2012-01-07 79 views
0

我已经使用了jQuery页面布局。现在我这段代码在jQuery的拖放框中拖动元素

jQuery(function() { 
    jQuery(".component").draggable({ 
    // use a helper-clone that is append to 'body' so is not 'contained' by a pane 
    helper: function() { return jQuery(this).clone().appendTo('body').css('zIndex',5).show(); }, 
    cursor: 'move' 
    }); 

    jQuery('.ui-layout-center').droppable({ 
    accept: '.component', 
    drop: function() { show('.component') } 
    }); 
}); 

拖动的元素到页面dropable,但现在我不能再拖动到页面中dropable元素。我在代码中犯了什么错误吗?

+0

我得到与上面的代码作为函数_show_ JavaScript错误是undefi斯内德。它是一个自定义函数,或者你想使用jQuery的['.show()'](http://api.jquery.com/show/) – andyb 2012-01-07 14:11:13

回答

0

使用这个模板为您Dragable元素

$(".component").draggable({  
    revert: "invalid", // when not dropped, the item will revert back to its initial position 
    containment: "#Content", // stick to demo-frame if present    
    helper: "clone", 
    cursor: "move" 
}); 
+0

它没有工作。我之前检查过它,我认为它不应该在这里使用。 – Jackson 2012-01-07 14:26:14

0

在投掷的,因为有人说,节目是不正确调用(参见JQ文档)。无论如何,我认为安装的附加拖动的元素到UI布局代码......这就是我在过去使用克隆的,不知道到底是什么你正在尝试做的:)

jQuery(function() { 
    jQuery(".component").draggable({ 

    helper: function() { return $(this).clone().css({'zIndex':5,'background-color':'red'}); }, 
    cursor: 'move' 
    }); 

    jQuery('.ui-layout-center').droppable({ 
     accept: '.component' , 
     drop: function (event, ui) {$(this).append($(ui.draggable).clone()); } 
    }); 
}); 
0

你的错误是

*您使用的展()不正确的语法

由莱恩试试这个另一种逻辑(修改)

jQuery(document).ready(function() { 
     jQuery(".component").draggable({ 
      helper: function() { return $(this).clone().appendTo('body').css({'zIndex':5,'background-color':'red'}); }, 
      cursor: 'move' 
     }); 
     jQuery('.ui-layout-center').droppable({ 
      accept: '.component' , 
      drop: function (event, ui) {$(this).append($(ui.draggable).clone()); }//This is to append the clone in '.ui-layout-center' when dropped 
     }); 
    });