<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>index</title>
<style>
img{
cursor: pointer;
position: absolute;
left: 0px;
top: 0px;
}
</style>
</head>
<body>
<img src="dlam.jpg" id="imgid" >
</body>
<script>
imgobj=document.getElementById('imgid');
xl=0;//起始位置为0
xs=10;//增加量为10
yl=0;
ys=10;
document.onkeydown=function(event){
kc=event.keyCode;
switch(kc){
case 37://←
xl-=xs;
imgobj.style.left=xl+'px';
break;
case 38://↑
yl-=ys;
imgobj.style.top=yl+'px';
break;
case 39://→
xl+=xs;
imgobj.style.left=xl+'px';
break;
case 40://↓
yl+=ys;
imgobj.style.top=yl+'px';
break;
}
}
</script>
</html>