<img src="data:images/hot.jpg" alt="" id="imgId" class="img1"/>
</body>
<script>
var imgObj=document.getElementById("imgId");
var xs=0;
var xv=10;
var ys=0;
var yv=30;
document.onkeydown=function(event){ //实现图片的移动
kc=event.keyCode;
console.log(kc);
switch(kc){
case 37:
xs-=xv;imgObj.style.left=xs+"px";
document.body.style.background="#567";
break;
case 38:ys-=yv;imgObj.style.top=ys+"px";break;
case 39:xs+=xv;imgObj.style.left=xs+"px";break;
case 40:ys+=yv;imgObj.style.top=ys+"px";break;
}
}
</script>