Código Javascript
:
Ver originalthis.keys={ left:false, top:false, rigth:false, bottom:false };
this.keyboard = function(){
$(document).keydown(function(e){
if(e.keyCode == '65'){
self.keys.left=true;
}
if(e.keyCode == '68'){
self.keys.right=true;
}
if(e.keyCode == '87'){
self.keys.top=true;
}
if(e.keyCode == '83'){
self.keys.bottom=true;
}
self.move();
});
$(document).keyup(function(e){
if(e.keyCode == '65'){
self.keys.left=false;
}
if(e.keyCode == '68'){
self.keys.right=false;
}
if(e.keyCode == '87'){
self.keys.top=false;
}
if(e.keyCode == '83'){
self.keys.bottom=false;
}
});
};
this.move = function(){
var x = self.div.offset().left;
var y = self.div.offset().top;
if (this.keys.left) x-=self.pixMove;
if (this.keys.right) x+=self.pixMove;
if (this.keys.top) y-=self.pixMove;
if (this.keys.bottom) y-=self.pixMove;
self.div.css('left',x+'px');
self.div.css('top',y+'px');
};