2008年8月29日

跟随鼠标的三色彩带

代码效果:跟随鼠标的三色彩带


代码如下:


<!--将以下代码加入HTML的<Body></Body>之间--><br /><br /><script language="JavaScript"><br /><!-- <br />var a_Colour='fff000';<br />var b_Colour='00ff00';<br />var c_Colour='ff00ff';<br />var Size=120;<br /><br />var YDummy=new Array(),XDummy=new Array(),xpos=0,ypos=0,ThisStep=0;step=0.6;<br />if (document.layers){<br />window.captureEvents(Event.MOUSEMOVE);<br />function nsMouse(evnt){<br />xpos = window.pageYOffset+evnt.pageX+6;<br />ypos = window.pageYOffset+evnt.pageY+16;<br />}<br />window.onMouseMove = nsMouse;<br />}<br />else if (document.all)<br />{<br />function ieMouse(){<br />xpos = document.body.scrollLeft+event.x+6;<br />ypos = document.body.scrollTop+event.y+16;<br />}<br />document.onmousemove = ieMouse;<br />}<br /><br />function swirl(){<br />for (i = 0; i < 3; i++)<br /> { <br /> YDummy[i]=ypos+Size*Math.sin((1*Math.sin((ThisStep)/10))+i*2)*Math.sin((ThisStep)/4);<br /> XDummy[i]=xpos+Size*Math.cos((1*Math.sin((ThisStep)/10))+i*2)*Math.sin((ThisStep)/4);<br /> }<br />ThisStep+=step;<br />setTimeout('swirl()',10);<br />}<br /><br />var amount=10;<br />if (document.layers){<br />for (i = 0; i < amount; i++)<br />{<br />document.write('<layer name=nsa'+i+' top=0 left=0 width='+i/2+' height='+i/2+' bgcolor='+a_Colour+'></layer>');<br />document.write('<layer name=nsb'+i+' top=0 left=0 width='+i/2+' height='+i/2+' bgcolor='+b_Colour+'></layer>');<br />document.write('<layer name=nsc'+i+' top=0 left=0 width='+i/2+' height='+i/2+' bgcolor='+c_Colour+'></layer>');<br />}<br />}<br />else if (document.all){<br />document.write('<div id="ODiv" style="position:absolute;top:0px;left:0px">'<br />+'<div id="IDiv" style="position:relative">');<br />for (i = 0; i < amount; i++)<br />{<br />document.write('<div id=x style="position:absolute;top:0px;left:0px;width:'+i/2+';height:'+i/2+';background:'+a_Colour+';font-size:'+i/2+'"></div>');<br />document.write('<div id=y style="position:absolute;top:0px;left:0px;width:'+i/2+';height:'+i/2+';background:'+b_Colour+';font-size:'+i/2+'"></div>');<br />document.write('<div id=z style="position:absolute;top:0px;left:0px;width:'+i/2+';height:'+i/2+';background:'+c_Colour+';font-size:'+i/2+'"></div>');<br />}<br />document.write('</div></div>');<br />}<br />function prepos(){<br />var ntscp=document.layers;<br />var msie=document.all;<br />if (document.layers){<br />for (i = 0; i < amount; i++)<br />{<br /> if (i < amount-1) <br /> {<br /> ntscp['nsa'+i].top=ntscp['nsa'+(i+1)].top;ntscp['nsa'+i].left=ntscp['nsa'+(i+1)].left;<br /> ntscp['nsb'+i].top=ntscp['nsb'+(i+1)].top;ntscp['nsb'+i].left=ntscp['nsb'+(i+1)].left;<br /> ntscp['nsc'+i].top=ntscp['nsc'+(i+1)].top;ntscp['nsc'+i].left=ntscp['nsc'+(i+1)].left;<br /> } <br />else <br /> {<br /> ntscp['nsa'+i].top=YDummy[0];ntscp['nsa'+i].left=XDummy[0];<br /> ntscp['nsb'+i].top=YDummy[1];ntscp['nsb'+i].left=XDummy[1];<br /> ntscp['nsc'+i].top=YDummy[2];ntscp['nsc'+i].left=XDummy[2];<br /> }<br />}<br />}<br />else if (document.all){<br />for (i = 0; i < amount; i++)<br />{<br /> if (i < amount-1) <br /> {<br /> msie.x[i].style.top=msie.x[i+1].style.top;msie.x[i].style.left=msie.x[i+1].style.left;<br /> msie.y[i].style.top=msie.y[i+1].style.top;msie.y[i].style.left=msie.y[i+1].style.left;<br /> msie.z[i].style.top=msie.z[i+1].style.top;msie.z[i].style.left=msie.z[i+1].style.left;<br /> } <br />else <br /> {<br /> msie.x[i].style.top=YDummy[0];msie.x[i].style.left=XDummy[0];<br /> msie.y[i].style.top=YDummy[1];msie.y[i].style.left=XDummy[1];<br /> msie.z[i].style.top=YDummy[2];msie.z[i].style.left=XDummy[2];<br /> }<br />}<br />}<br />setTimeout("prepos()",10);<br />}<br />function Start(){<br />swirl(),prepos()<br />}<br />window.onload=Start;<br />// --><br /></script><br />

没有评论: