2008年8月29日

跟随鼠标的表盘

代码效果:跟随鼠标的表盘。


代码如下:


<!--将以下代码加入HTML的<Body></Body>之间--><br /><br /><SCRIPT language=JavaScript> <br /><!-- <br />dCol="0000FF"<br />fCol="FF0000"<br />sCol="00FF00"<br />mCol="000000"<br />hCol="000000"<br />ClockHeight=40; <br />ClockWidth=40; <br />ClockFromMouseY=0; <br />ClockFromMouseX=100; <br /> <br />d=new Array("星期日","星期一","星期二","星期三","星期四","星期五","星期六"); <br />m=new Array("1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"); <br />date=new Date(); <br />day=date.getDate(); <br />year=date.getYear(); <br />if (year < 2000) year=year+1900; <br />TodaysDate="年 "+m[date.getMonth()]+" "+day+"日 "+d[date.getDay()]+" "+year; <br />D=TodaysDate.split(''); <br />H='...'; <br />H=H.split(''); <br />M='....'; <br />M=M.split(''); <br />S='.....'; <br />S=S.split(''); <br />Face='1 2 3 4 5 6 7 8 9 10 11 12'; <br />font='Arial'; <br />size=1; <br />speed=0.6; <br />ns=(document.layers); <br />ie=(document.all); <br />Face=Face.split(' '); <br />n=Face.length; <br />a=size*10; <br />ymouse=0; <br />xmouse=0; <br />scrll=0; <br />props="<font face="+font+" size="+size+" color="+fCol+">"; <br />props2="<font face="+font+" size="+size+" color="+dCol+">"; <br />Split=360/n; <br />Dsplit=360/D.length; <br />HandHeight=ClockHeight/4.5 <br />HandWidth=ClockWidth/4.5 <br />HandY=-7; <br />HandX=-2.5; <br />scrll=0; <br />step=0.06; <br />currStep=0; <br />y=new Array();x=new Array();Y=new Array();X=new Array(); <br />for (i=0; i < n; i++){y[i]=0;x[i]=0;Y[i]=0;X[i]=0} <br />Dy=new Array();Dx=new Array();DY=new Array();DX=new Array(); <br />for (i=0; i < D.length; i++){Dy[i]=0;Dx[i]=0;DY[i]=0;DX[i]=0} <br />if (ns){ <br />for (i=0; i < D.length; i++) <br />document.write('<layer name="nsDate'+i+'" top=0 left=0 height='+a+' width='+a+'><center>'+props2+D[i]+'</font></center></layer>'); <br />for (i=0; i < n; i++) <br />document.write('<layer name="nsFace'+i+'" top=0 left=0 height='+a+' width='+a+'><center>'+props+Face[i]+'</font></center></layer>'); <br />for (i=0; i < S.length; i++) <br />document.write('<layer name=nsSeconds'+i+' top=0 left=0 width=15 height=15><font face=Arial size=3 color='+sCol+'><center><b>'+S[i]+'</b></center></font></layer>'); <br />for (i=0; i < M.length; i++) <br />document.write('<layer name=nsMinutes'+i+' top=0 left=0 width=15 height=15><font face=Arial size=3 color='+mCol+'><center><b>'+M[i]+'</b></center></font></layer>'); <br />for (i=0; i < H.length; i++) <br />document.write('<layer name=nsHours'+i+' top=0 left=0 width=15 height=15><font face=Arial size=3 color='+hCol+'><center><b>'+H[i]+'</b></center></font></layer>'); <br />} <br />if (ie){ <br />document.write('<div id="Od" style="position:absolute;top:0px;left:0px"><div style="position:relative">'); <br />for (i=0; i < D.length; i++) <br />document.write('<div id="ieDate" style="position:absolute;top:0px;left:0;height:'+a+';width:'+a+';text-align:center">'+props2+D[i]+'</font></div>'); <br />document.write('</div></div>'); <br />document.write('<div id="Of" style="position:absolute;top:0px;left:0px"><div style="position:relative">'); <br />for (i=0; i < n; i++) <br />document.write('<div id="ieFace" style="position:absolute;top:0px;left:0;height:'+a+';width:'+a+';text-align:center">'+props+Face[i]+'</font></div>'); <br />document.write('</div></div>'); <br />document.write('<div id="Oh" style="position:absolute;top:0px;left:0px"><div style="position:relative">'); <br />for (i=0; i < H.length; i++) <br />document.write('<div id="ieHours" style="position:absolute;width:16px;height:16px;font-family:Arial;font-size:16px;color:'+hCol+';text-align:center;font-weight:bold">'+H[i]+'</div>'); <br />document.write('</div></div>'); <br />document.write('<div id="Om" style="position:absolute;top:0px;left:0px"><div style="position:relative">'); <br />for (i=0; i < M.length; i++) <br />document.write('<div id="ieMinutes" style="position:absolute;width:16px;height:16px;font-family:Arial;font-size:16px;color:'+mCol+';text-align:center;font-weight:bold">'+M[i]+'</div>'); <br />document.write('</div></div>') <br />document.write('<div id="Os" style="position:absolute;top:0px;left:0px"><div style="position:relative">'); <br />for (i=0; i < S.length; i++) <br />document.write('<div id="ieSeconds" style="position:absolute;width:16px;height:16px;font-family:Arial;font-size:16px;color:'+sCol+';text-align:center;font-weight:bold">'+S[i]+'</div>'); <br />document.write('</div></div>') <br />} <br />(ns)?window.captureEvents(Event.MOUSEMOVE):0; <br />function Mouse(evnt){ <br />ymouse = (ns)?evnt.pageY+ClockFromMouseY-(window.pageYOffset):event.y+ClockFromMouseY; <br />xmouse = (ns)?evnt.pageX+ClockFromMouseX:event.x+ClockFromMouseX; <br />} <br />(ns)?window.onMouseMove=Mouse:document.onmousemove=Mouse; <br />function ClockAndAssign(){ <br />time = new Date (); <br />secs = time.getSeconds(); <br />sec = -1.57 + Math.PI * secs/30; <br />mins = time.getMinutes(); <br />min = -1.57 + Math.PI * mins/30; <br />hr = time.getHours(); <br />hrs = -1.575 + Math.PI * hr/6+Math.PI*parseInt(time.getMinutes())/360; <br />if (ie){ <br />Od.style.top=window.document.body.scrollTop; <br />Of.style.top=window.document.body.scrollTop; <br />Oh.style.top=window.document.body.scrollTop; <br />Om.style.top=window.document.body.scrollTop; <br />Os.style.top=window.document.body.scrollTop; <br />} <br />for (i=0; i < n; i++){ <br />var F=(ns)?document.layers['nsFace'+i]:ieFace[i].style; <br />F.top=y[i] + ClockHeight*Math.sin(-1.0471 + i*Split*Math.PI/180)+scrll; <br />F.left=x[i] + ClockWidth*Math.cos(-1.0471 + i*Split*Math.PI/180); <br />} <br />for (i=0; i < H.length; i++){ <br />var HL=(ns)?document.layers['nsHours'+i]:ieHours[i].style; <br />HL.top=y[i]+HandY+(i*HandHeight)*Math.sin(hrs)+scrll; <br />HL.left=x[i]+HandX+(i*HandWidth)*Math.cos(hrs); <br />} <br />for (i=0; i < M.length; i++){ <br />var ML=(ns)?document.layers['nsMinutes'+i]:ieMinutes[i].style; <br />ML.top=y[i]+HandY+(i*HandHeight)*Math.sin(min)+scrll; <br />ML.left=x[i]+HandX+(i*HandWidth)*Math.cos(min); <br />} <br />for (i=0; i < S.length; i++){ <br />var SL=(ns)?document.layers['nsSeconds'+i]:ieSeconds[i].style; <br />SL.top=y[i]+HandY+(i*HandHeight)*Math.sin(sec)+scrll; <br />SL.left=x[i]+HandX+(i*HandWidth)*Math.cos(sec); <br />} <br />for (i=0; i < D.length; i++){ <br />var DL=(ns)?document.layers['nsDate'+i]:ieDate[i].style; <br />DL.top=Dy[i] + ClockHeight*1.5*Math.sin(currStep+i*Dsplit*Math.PI/180)+scrll; <br />DL.left=Dx[i] + ClockWidth*1.5*Math.cos(currStep+i*Dsplit*Math.PI/180); <br />} <br />currStep-=step; <br />} <br />function Delay(){ <br />scrll=(ns)?window.pageYOffset:0; <br />Dy[0]=Math.round(DY[0]+=((ymouse)-DY[0])*speed); <br />Dx[0]=Math.round(DX[0]+=((xmouse)-DX[0])*speed); <br />for (i=1; i < D.length; i++){ <br />Dy[i]=Math.round(DY[i]+=(Dy[i-1]-DY[i])*speed); <br />Dx[i]=Math.round(DX[i]+=(Dx[i-1]-DX[i])*speed); <br />} <br />y[0]=Math.round(Y[0]+=((ymouse)-Y[0])*speed); <br />x[0]=Math.round(X[0]+=((xmouse)-X[0])*speed); <br />for (i=1; i < n; i++){ <br />y[i]=Math.round(Y[i]+=(y[i-1]-Y[i])*speed); <br />x[i]=Math.round(X[i]+=(x[i-1]-X[i])*speed); <br />} <br />ClockAndAssign(); <br />setTimeout('Delay()',40); <br />} <br />if (ns||ie)window.onload=Delay; <br />//--> <br /></SCRIPT><br />

1 条评论:

风释 说...

由于编辑器的问题,如果代码无法显示请连接

http://jiaoliudi.blog.hexun.com/cate.aspx?cateid=732507&cate=%bf%d5%bc%e4%bd%a8%c9%e8