//勾股定理求距离
function getDis(obj1,obj2){
var a = obj1.offsetLeft-obj2.offsetLeft;
var b = obj1.offsetTop-obj2.offsetTop;
return Math.sqrt(Math.pow(a,2) Math.pow(b,2));
}
//找到距离最近的
function findMin(obj){
var minDis = 999999999;
var minIndex = -1;
for(var i=0;i<aLi.length;i ){
if(obj==aLi[i])continue;
if(colTest(obj,aLi[i])){
var dis = getDis(obj,aLi[i]);
if(dis<minDis){
minDis = dis;
minIndex = i;
}
}
}
if(minIndex==-1){
return null;
}else{
return aLi[minIndex];
}
}
评论