Ciao io ho un elemento
Codice PHP:
<div id="div">
</div>
, che, dovrei spostare a sinistra, sopra, a destra e in basso a seconda del tasto premuto utilizzando document.onkeydown = keyDown(e); con questo:
Codice PHP:
document.onkeydown=keyDown;
function __() {
try{document.getElementById("div").innerHTML="Press an arrow.";}
catch(E){alert(E);}
}
function keyDown(e){
var cch = e.keyCode;
switch(cch){
default:
try{document.getElementById("div").innerHTML="\""+String.fromCharCode(cch)+"\" isn't an arrow.";}
catch(E){alert(E);};
return false;
break;
case 37:
//alert('Left');
try{document.getElementById("div").innerHTML="\u2190";}
catch(E){alert(E);}
break;
case 38:
//alert('Up');
try{document.getElementById("div").innerHTML="\u2191";}
catch(E){alert(E);}
break;
case 39:
//alert('Right');
try{document.getElementById("div").innerHTML="\u2192";}
catch(E){alert(E);}
break;
case 40:
//alert('Down');
try{document.getElementById("div").innerHTML="\u2193";}
catch(E){alert(E);}
break;
}
}
Sapendo che e.keyCode (vettore) mi restituisce un numero, come faccio a modificare la position dell'oggetto div?
Ho provato con document.getElementById("div").style.position.left =document.getElementById("div").style.position.lef t+1+"px"; ma non mi fa.