2010-01-19 78 views
1

我有一些問題,在jQuery中拖放,放置。Jquery拖放問題與位置,幫助!

這是我想實現:

  1. 您拖動一個div的克隆到另一個DIV這是「舞臺」
  2. 我需要克隆的位置,而不是原來的

這是迄今爲止我嘗試:

$(function() { 

$("#workspacemaster").droppable({ 
accept: '.draggable', 
drop: function(event, ui) 
{ 
} 

}); 

// Make images draggable. 
$("#draggable1").draggable({ 

    // Find original position of dragged image. 
    start: function(event, ui) { 

     // Show start dragged position of image. 
     var Startpos = $(this).position(); 
     $("div#start1").text("1 START: \nLeft: "+ Startpos.left + "\nTop: " + Startpos.top); 
    }, 
    cursor: 'move', 
    grid: [20, 20], 

    // Find position where image is dropped. 
    stop: function(event, ui) { 

     // Show dropped position. 
     var Stoppos = $(this).position(); 
     $("div#stop1").text("1 STOP: \nLeft: "+ Stoppos.left + "\nTop: " + Stoppos.top); 
    } 
}); 

}); 

回答

0

我想你應該在實現這個可棄,而不是拖動

$('#workspacemaster').droppable({ 
    accept: '.draggable', 
    drop: function(event, ui){ 
    //do something with $(ui.helper) or $(ui.draggable); 
    // this is scoped to the droppable 
    } 
}); 
0

我這樣做是爲了鉻,你敢拿必須使它跨瀏覽器:

$(".draggable").draggable({ 
    helper:"clone", 
    //this will take whatever css you have for .draggable and add opacity 
    opacity:0.7 
}); 


$('#workspacemaster').droppable(
    { 
    accept: ".pageControl", 
    drop: function(e,ui){ 
     $(this).append(
     $(ui.draggable).clone() 
     .css({ 
      position:"absolute", 
      top: e.clientY-e.offsetY, 
      left: e.clientX-e.offsetX 
     }) 
     .draggable({containment:"parent"}) 
    ); 
    } 
    } 
);