For each name, you have only to store the target position (positions to reach) an to calculate the distance with the drop position. If the distance(*) is less than few pixels (3, 7 or 15px, it depends of the scale), the script takes the target coordinates instead of the proposed by the user to let the name at the right place, otherwise the image is returned to its original position (which is given by this.ox and this.oy)...
Code:
// For example you define the names (a comma separated string to split in an array)
var arrNames="Aorta,Vena cava,right atrium,...".split(',');
// And the coordinates to reach (two values for each name - example only)
var arrLeftTop="256,42,387,59,789,25,...".split(',');
// You build you movable names to display in the page
str='';
for (var i=0;i<arrNames.length;ii++) str+='<p id="nms'+i+'" class="drag">'+arrNames[i]+'</p>';
document.getElementById("pge").innerHTML=str;
When the user drag a name, you have only (in the mouseup function) to find its id
this.trgObj.id which gives the value of its index
var index=Number(this.trgObj.id.substr(3));
and, finally, compare
this.trgObj.offsetLeft and
this.trgObj.offsetTop with
arrLftTop[2*i] and
arrLftTop[2*i+1] the corresponding coordinates where the name should be placed (a variant with an array of object with three keys name, left and top would be more readable).
See too the HTML tags
map and
area which could perhaps be useful...
You can choose many distances like : the Euclidian Math.sqrt(deltaLeft*deltaLeft+deltaTop*deltaTop) or others Math.abs(deltaLeft)+Math.abs(deltaTop) or Math.abs(deltaLeft+deltaTop)+Math.abs(deltaLeft-deltaTop)