// 显示大图
var smX=pos.left-smBoxLeft;
var smY=pos.top-smBoxTop;
var bigX=-(smX*$big_box.width()/floatBoxW);
var bigY=-(smY*$big_box.height()/floatBoxH);
var bigPos={
X:Math.floor(bigX),
Y:Math.floor(bigY)
};
$("#big-box img").eq(0).css({"top":bigPos.Y+"px","left":bigPos.X+"px"});
var smX=pos.left-smBoxLeft;
var smY=pos.top-smBoxTop;
var bigX=-(smX*$big_box.width()/floatBoxW);
var bigY=-(smY*$big_box.height()/floatBoxH);
var bigPos={
X:Math.floor(bigX),
Y:Math.floor(bigY)
};
$("#big-box img").eq(0).css({"top":bigPos.Y+"px","left":bigPos.X+"px"});
// 大图片运动
var moveX=left;
var moveY=top;
var moveBX=-Math.floor((left*objBigBox.offsetWidth/objFloatBox.offsetWidth));
var moveBY=-Math.floor((top*objBigBox.offsetHeight/objFloatBox.offsetHeight));
objBigBoxImage.style.left=moveBX+"px";
objBigBoxImage.style.top=moveBY+"px";
var moveX=left;
var moveY=top;
var moveBX=-Math.floor((left*objBigBox.offsetWidth/objFloatBox.offsetWidth));
var moveBY=-Math.floor((top*objBigBox.offsetHeight/objFloatBox.offsetHeight));
objBigBoxImage.style.left=moveBX+"px";
objBigBoxImage.style.top=moveBY+"px";
// 防止越界
left=left<0?0:(left>(objSmallBox.offsetWidth-objFloatBox.offsetWidth)?(objSmallBox.offsetWidth-objFloatBox.offsetWidth):left);
top=top<0?0:(top>(objSmallBox.offsetHeight-objFloatBox.offsetHeight)?(objSmallBox.offsetHeight-objFloatBox.offsetHeight):top);
left=left<0?0:(left>(objSmallBox.offsetWidth-objFloatBox.offsetWidth)?(objSmallBox.offsetWidth-objFloatBox.offsetWidth):left);
top=top<0?0:(top>(objSmallBox.offsetHeight-objFloatBox.offsetHeight)?(objSmallBox.offsetHeight-objFloatBox.offsetHeight):top);
最赞回答 / happyuzhou
其实?的求解就是一个比例问题,个人感觉老师的解法有点复杂。有x/A = ?/C,可以转化为:?=x*C/A其实将老师的式子化简可以得到上式的x/(B-A) = ?/(D-C) 且有条件 B/A = D/C成立x/[(B/A-1)*A] = ?/[(D/C-1)*C](x/A)/(B/A-1) = (?/C)/(D/C-1) 分母相等有x/A = ?/C
2016-07-31