2012-01-07 51 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 
     }); 
    });