2008年8月29日

跟随鼠标的重合文字

代码效果:跟随鼠标的重合文字


代码如下:


<!--将以下代码加入HTML的<Body></Body>之间--> <br /><script language="JavaScript1.2"> <br />var message='文字内容' <br />var messagecolor='FF0000' <br />var dismissafter=0 <br />var amount=5,ypos=0,xpos=0,Ay=0,Ax=0,By=0,Bx=0,Cy=0,Cx=0,Dy=0,Dx=0,Ey=0,Ex=0; <br />if (document.layers){ <br />for (i = 0; i < amount; i++) <br />{document.write('<layer name=ns'+i+' top=0 left=0><font face="宋体" size=10 color='+messagecolor+'>'+message+'</font></layer>')} <br />window.captureEvents(Event.MOUSEMOVE); <br />function nsmouse(evnt){xpos = evnt.pageX;ypos = evnt.pageY;makefollow()} <br />} <br />else if (document.all){ <br />document.write("<div id='outer' style='position:absolute;top:0px;left:0px'>"); <br />document.write("<div id='inner' style='position:relative'>"); <br />for (i = 0; i < amount; i++) <br />{document.write('<div id="text"'+i+' style="position:absolute;top:0px;left:0px;font-family:宋体;font-size:16px;color:'+messagecolor+'">'+message+'</div>')} <br />document.write("</div>"); <br />document.write("</div>"); <br />function iemouse(){ypos = document.body.scrollTop + event.y;xpos = document.body.scrollLeft + event.x;makefollow()} <br />} <br />function makefollow(){ <br />if (document.layers){ <br />document.layers["ns0"].top=ay;document.layers["ns0"].left=ax; <br />document.layers["ns1"].top=by;document.layers["ns1"].left=bx; <br />document.layers["ns2"].top=cy;document.layers["ns2"].left=cx; <br />document.layers["ns3"].top=Dy;document.layers["ns3"].left=Dx; <br />document.layers["ns4"].top=Ey;document.layers["ns4"].left=Ex; <br />} <br />else if (document.all){ <br />outer.all.inner.all[0].style.pixelTop=ay;outer.all.inner.all[0].style.pixelLeft=ax; <br />outer.all.inner.all[1].style.pixelTop=by;outer.all.inner.all[1].style.pixelLeft=bx; <br />outer.all.inner.all[2].style.pixelTop=cy;outer.all.inner.all[2].style.pixelLeft=cx; <br />outer.all.inner.all[3].style.pixelTop=Dy;outer.all.inner.all[3].style.pixelLeft=Dx; <br />outer.all.inner.all[4].style.pixelTop=Ey;outer.all.inner.all[4].style.pixelLeft=Ex; <br />} <br />} <br />function move(){ <br />if (dismissafter!=0) <br />setTimeout("hidetrail()",dismissafter*1000) <br /> <br />if (document.layers){window.onMouseMove = nsmouse} <br />else if (document.all){window.document.onmousemove = iemouse} <br />ey = Math.round(Ey+=((ypos+20)-Ey)*2/2);ex = Math.round(Ex+=((xpos+20)-Ex)*2/2); <br />dy = Math.round(Dy+=(ey - Dy)*2/4);dx = Math.round(Dx+=(ex - Dx)*2/4); <br />cy = Math.round(Cy+=(dy - Cy)*2/6);cx = Math.round(Cx+=(dx - Cx)*2/6); <br />by = Math.round(By+=(cy - By)*2/8);bx = Math.round(Bx+=(cx - Bx)*2/8); <br />ay = Math.round(Ay+= (by - Ay)*2/10);ax = Math.round(Ax+= (bx - Ax)*2/10); <br />makefollow(); <br />jumpstart=setTimeout('move()',10); <br />} <br /> <br />function hidetrail(){ <br />if (document.all){ <br />for (i2=0;i2<amount;i2++){ <br />outer.all.inner.all[i2].style.visibility="hidden" <br />clearTimeout(jumpstart) <br />} <br />} <br />else if (document.layers){ <br />for (i2=0;i2<amount;i2++){ <br />temp="ns"+i2 <br />document.layers[temp].visibility="hide" <br />clearTimeout(jumpstart) <br />} <br />} <br />} <br /> <br />window.onload=move; <br />//--> <br /></script> <br />

没有评论: