【发布时间】:2013-11-26 14:52:07
【问题描述】:
我有一个根据鼠标指针移动的位置旋转的图像。我想要完成的是这个。如果指针离得太近,图像应该一起停止移动。
这里有一张图片让它更清楚一点:
这是旋转的代码:
$(window).on('mousemove', function (e) {
//Current position
var p1 = {
x: player.offset().left,
y: player.offset().top
};
//Future position
var p2 = {
x: e.offsetX,
y: e.offsetY
};
//Angle between them in degrees
var angleDeg = Math.atan2(p2.y - p1.y, p2.x - p1.x) * 180 / Math.PI;
angleDeg -= 90;
//Animate the whole thing
player.css('-webkit-transform', 'rotate(' + angleDeg + 'deg)');
});
这是我迄今为止尝试过的,但没有成功:
function tooClose(object1, object2){
if (object1.x < object2.x && object1.x + object1.width > object2.x &&
object1.y < object2.y && object1.y + object1.height > object2.y) {
return true;
}
}
谢谢!
【问题讨论】:
标签: javascript object rotation mouseover