编码:
$(document).ready(function(){
var player = $('#player');
//Checks to see which key is pressed down
$(window).on('mousemove', function (e) {
//Current position
var p1 = {
x: player.offsetLeft,
y: player.offsetTop
};
//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;
if(angleDeg >= 360){
angleDeg -= 360;
}
player.css('-webkit-transform', 'rotate(' + angleDeg + 'deg)');
});
});
什么都没发生。如果我写类似:
$(document).mousemove(function(e){
$("#player").css({left:e.pageX, top:e.pageY});
});
图像跟随鼠标。我只想让它旋转。
谢谢!