Inseguimento del Mouse
Di Trantor

Luna
<html> <head> <title>Inseguimento del Mouse</title> <style type="text/css"><!-- #Luna {position:absolute} // --> </style> <script type="text/javascript"><!-- n = (document.layers) ? 1:0 ie = (document.all) ? 1:0 var cx=0,cy=0,tempo=10,xl=0,yl=0,rl=30,angl=0,val=20 function Posizione() { if (ie) { cx=event.clientX+document.body.scrollLeft; cy=event.clientY+document.body.scrollTop; } if (n) { window.captureEvents(Event.MOUSEMOVE); window.onmousemove=PosMouseNS; } } function PosMouseNS(e) { cx=e.pageX cy=e.pageY } function Muovi() { with (Math) { angl=angl+PI/val xl=cx+cos(angl)*rl yl=cy-sin(angl)*rl if (ie) { document.all.Luna.style.left =xl-10 document.all.Luna.style.top =yl-10 } if (n) { document.layers.Luna.left =xl-10 document.layers.Luna.top =yl-10 } } } setInterval("Muovi()",tempo) // --> </script> </head> <body onLoad="Posizione()" onMousemove="Posizione()" onScroll="Posizione()"> <div id="Luna"><img src="luna.gif" alt="Luna" width="20" height="20"></div> </body> </html>
Lezioni di Dynamic HTML