<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>_</title>
<script src="
http://libs.baidu.com/jquery/1.11.1/jquery.min.js"></script></head>
<script type="text/javascript">
$(function(){
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
var img = new Image();
img.src = "
https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo/bd_logo1_31bdc765.png"; img.onload = function(){
draw(this, 10, 10);
};
function draw(img, x, y){
if(img){
this.img = img;
this.x = x;
this.y = y;
this.width = img.width;
this.height = img.height;
}else{
if(!this.img) return;
ctx.clearRect(this.x, this.y, this.x + this.width, this.y + this.height);
img = this.img;
x += this.x;
y += this.y;
this.x = x;
this.y = y;
}
ctx.drawImage(img, x, y);
}
var size = 5;
$(document.body).keydown(function(event){
switch(event.keyCode){
case 37: draw(null, -size, 0); break;
case 38: draw(null, 0, -size); break;
case 39: draw(null, size, 0); break;
case 40: draw(null, 0, size); break;
}
});
});
</script>
<body>
<canvas id="canvas" width="1000" height="500"></canvas>
</body>
</html>