キーボードの矢印キーで移動できる画像(event.keyCode)
<html> <head> <title>矢印キーで移動できる画像</title> <script language="JavaScript"> <!-- function move(){ // 画像の移動 x = 0; y = 0; switch(event.keyCode) { case 37:x = -5; break; case 38:y = -5; break; case 39:x = 5; break; case 40:y = 5; break; } img1.style.pixelLeft += x; img1.style.pixelTop += y; } //--> </script> </head> <body onKeydown="move()"> <img src="../../sample/img/img2.gif" ID="img1" STYLE="position:absolute;top:50;left:0"> キーボードの矢印キーで移動できます </body> </html>
〔 実行する 〕