2008年8月29日

跟随鼠标的花絮

代码效果:跟随鼠标的花絮


代码如下:


<!--将以下代码加入HTML的<Body></Body>之间--><br /><SCRIPT language=JavaScript><br /><!-- <br />//To add more stars simply add more colours in below array!!<br />colours=new Array('ff0000','00ff00','3366ff','ff00ff','ffa500','ffffff','fff000')<br /><br />//Alter nothing below!!<br />amount=colours.length;<br />YgetDelay=0,XgetDelay=0,Ydelay=0,Xdelay=0,ns=(document.layers)?1:0,step=0.2,currStep=0,my=0,mx=0;<br />if (ns){<br />for (i=0; i < amount; i++)<br />document.write('<LAYER NAME="nsstars'+i+'" BGCOLOR='+colours[i]+' CLIP="0,0,2,2"></LAYER>');<br />}<br />else{<br />document.write('<div id="ie" style="position:absolute;top:0;left:0;"><div style="position:relative">');<br />for (i=0; i < amount; i++)<br />document.write('<span id="iestars" style="position:absolute;top:0;left:0;width:2px;height:2px;background:'+colours[i]+';font-size:2px"></span>');<br />document.write('</div></div>');<br />}<br />if (ns){<br />window.captureEvents(Event.MOUSEMOVE);<br />function nMouse(evnt){ <br />my=evnt.pageY;mx=evnt.pageX<br />}<br />window.onMouseMove=nMouse;<br />}<br />else{<br />function iMouse(){<br />my=event.y;mx=event.x;<br />}<br />document.onmousemove=iMouse<br />}<br />function stars(){<br />if (!ns)ie.style.top=document.body.scrollTop;<br />for (i=0; i < amount; i++)<br /> {<br /> var layer=(document.layers)?document.layers["nsstars"+i]:iestars[i].style; <br /> layer.top= Ydelay+100*Math.sin((5*Math.sin((currStep-15.99)/10))+i*70)*Math.sin((currStep)/10)*Math.cos((currStep+i*25)/10); <br /> layer.left=Xdelay+180*Math.cos((5*Math.sin((currStep-15.99)/10))+i*70)*Math.sin((currStep)/10)*Math.cos((currStep+i*25)/10);<br /> }<br />currStep+=step;<br />}<br /><br />function delay(){<br />Ydelay = YgetDelay+=(my-YgetDelay)*1/20;<br />Xdelay = XgetDelay+=(mx-XgetDelay)*1/20;<br />stars();<br />setTimeout('delay()',10);<br />}<br />delay();<br />//--><br /></SCRIPT><br />

没有评论: