Per il momento so farlo solo in Firefox.
<script> function oggetto(nome){ var MioNome=nome; var Sinistra=Number((document.getElementById(MioNome).style.left).replace("px","")); var Alto=Number((document.getElementById(MioNome).style.top).replace("px","")); var Larghezza=Number((document.getElementById(MioNome).style.width).replace("px","")); var Altezza=Number((document.getElementById(MioNome).style.height).replace("px","")); var intX=1; var intY=1; var Intervallo; this.step=function(){ if((Sinistra>900)||(Sinistra<0)) intX=-intX if((Alto>600)||(Alto<0)) intY=-intY Sinistra+=intX Alto+=intY document.getElementById(MioNome).style.left=Sinistra; document.getElementById(MioNome).style.top=Alto; } this.muovi=function(){ Intervallo=window.setInterval(function(oggetto){oggetto.step()},10,this); } } function crea(){ for(var n=0;n<document.getElementsByTagName("img").length;n++) { var DivId=document.getElementsByTagName("img")[n].id; window[DivId] = new oggetto(DivId); } } function clic(e,){ window[e.currentTarget.id].muovi(); } </script> <body onLoad="crea();"> <img id="ciccio" style="width:50px;height:50px;position:absolute;top:0px" src="pallone.gif" onClick="clic(event)"> <img id="pippo" style="width:50px;height:50px;position:absolute;top:100px" src="pallone.gif" onClick="clic(event)"> <img id="mimmo" style="width:50px;height:50px;position:absolute;top:200px" src="pallone.gif" onClick="clic(event)"> </body>
Nessun commento:
Posta un commento