我有以下代码:
var currX = 0;
var currY = 0;
var player = $('#player');
//Checks to see which key is pressed down
$(window).on('mousedown', function(e) {
currX = e.offsetX;
currY = e.offsetY;
console.log(e.offsetX + ', ' + e.offsetY);
});
player.css({
left: function(index,value) { return (value + currX + 'px'); },
top: function(index,value) { return (value + currY + 'px'); }
});
图像根本不动。我console.log
输出了两个偏移量,它们被正确打印出来。
谢谢!