我有一个图像根据鼠标指针移动的位置而旋转。我试图完成的是这个。如果指针太靠近,图像应停止移动。如果鼠标指针太靠近,请停止旋转图像
这里是一个图像,使其更清楚一点:
下面是代码为旋转:
$(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;
}
}
谢谢!
这确实做到了!谢谢! –
如果你删除了'-webkit -',这可以在Chrome和Firefox中使用;) – core1024
@ core1024 -webkit-用于Chrome和Safari。 -moz-是为火狐:) –