Javascript Jquery可拖动图像拖放到左上角所在的div

Javascript Jquery可拖动图像拖放到左上角所在的div,javascript,jquery,html,drag-and-drop,Javascript,Jquery,Html,Drag And Drop,可升降潜水器: <div id="invContainer" style="width:100px; height:100px;> <div id="inv_0-0" class="inventory" style="position: relative; float:left; width:50px; height:50px; background-color: #fff;"></div> <div id="inv_1-0" class="in

可升降潜水器:

<div id="invContainer" style="width:100px; height:100px;>
  <div id="inv_0-0" class="inventory" style="position: relative; float:left; width:50px; height:50px; background-color: #fff;"></div>
  <div id="inv_1-0" class="inventory" style="position: relative; float:left; width:50px; height:50px; background-color: #000;"></div>
  <div id="inv_0-1" class="inventory" style="position: relative; float:left; width:50px; height:50px; background-color: #000;"></div>
  <div id="inv_1-1" class="inventory" style="position: relative; float:left; width:50px; height:50px; background-color: #fff;"></div>
</div>

首先查看JQuery DragTable是否具有标准的位置捕捉功能。
Oterwise您必须将图像“移动”到您想要的位置。
用这样的一点数学:

function ondrop_move(obj) {
    w = obj.width();
    h = obj.height();
    new_top = obj.position().top + (h / 2);
    new_left = obj.position().left + (w / 2)
    obj.css('left', new_left);
    obj.css('top', new_top);
}