[朝花夕阳拾]漂亮的时钟特效

  昨天回拾了很久以前的时钟特效代码,不过在FF上实行不能,感觉实在可惜,今天起来抽了一点点时间做了些微改动后终于动起来了。感动啊!这些年来的确长进不少了呢。哈哈。

<SCRIPT language=JavaScript> dCol='66FF00';//date colour. fCol='FF6600';//face colour. sCol='660099';//seconds colour. mCol='3366FF';//minutes colour. hCol='569923';//hours colour. gCol='0099FF';//第三行文字 colour. ClockHeight=40;//钟高. ClockWidth=40;//钟宽. ClockFromMouseY=80;//钟中心离MOUSE嘅纵坐标. ClockFromMouseX=80;//钟中心离MOUSE嘅横坐标. //Alter nothing below! Alignments will be lost!(E条警告可以当渠傻嘅) d=new Array("SUNDAY","MONDAY","TUESDAY","WEDNESDAY","THURSDAY","FRIDAY","SATURDAY"); //创建日期数组. m=new Array("JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE","JULY","AUGUST","SEPTEMBER","OCTOBER","NOVEMBER","DECEMBER"); //创建月份数组. date=new Date();//获取日期. day=date.getDate(); year=date.getYear(); if (year < 2000) year=year+1900; TodaysDate=" "+d[date.getDay()]+" "+day+" "+m[date.getMonth()]+" "+year;//(日期栏显示格式) D=TodaysDate.split('');//数组间隔. H='...';//时、分、秒针样式 H=H.split(''); M='....'; M=M.split(''); S='.....'; S=S.split(''); T='屏 闭 那 段 会 令 其 他 人 困 扰 的 文 字 ';//字符串.(可更换你想讲嘅嘢嘅地方...支持中文...此部分为我自制...大家亦都可以学我加多几行...不过可能D人会更加烦...呵呵...) T=T.split(''); Face='1 2 3 4 5 6 7 8 9 10 11 12';//钟面. font='Arial';//钟面字体.(想换字体就换''号入面嘅嘢,例:font='宋体',但初哥最好换个变量储存...) size=3;//字体大小. speed=0.6;//拉动时速. Face=Face.split(' '); n=Face.length; a=size*10; ymouse=0; xmouse=0; scrll=0; props="<font face="+font+" size="+size+" color="+fCol+"><B>"; props2="<font face="+font+" size="+size+" color="+dCol+"><B>"; props3="<font face="+font+" size="+size+" color="+gCol+"><B>"; Split=360/n; Dsplit=360/D.length; Tsplit=360/T.length; HandHeight=ClockHeight/4.5 HandWidth=ClockWidth/4.5 HandY=-7; HandX=7; scrll=0; step=0.015;//顺时针转速. rstep=0.03;//逆时针转速 currStep=0; rigStep=0;//以下为层算法. y=new Array();x=new Array();Y=new Array();X=new Array(); for (i=0; i < n; i++){y[i]=0;x[i]=0;Y[i]=0;X[i]=0} Dy=new Array();Dx=new Array();DY=new Array();DX=new Array(); for (i=0; i < D.length; i++){Dy[i]=0;Dx[i]=0;DY[i]=0;DX[i]=0} Ty=new Array();Tx=new Array();TY=new Array();TX=new Array(); for (i=0; i < T.length; i++){Ty[i]=0;Tx[i]=0;TY[i]=0;TX[i]=0} document.write('<div id="Ot" style="position:absolute;top:0px;left:0px"><div style="position:relative" mce_style="position:relative">'); for (i=0; i < T.length; i++) document.write('<div id="Text'+i+'" style="position:absolute;top:0px;left:0;height:'+a+';width:'+a+';text-align:center">'+props3+T[i]+'</B></font></div>'); document.write('</div></div>'); document.write('<div id="Od" style="position:absolute;top:0px;left:0px"><div style="position:relative" mce_style="position:relative">'); for (i=0; i < D.length; i++) document.write('<div id="ieDate'+i+'" style="position:absolute;top:0px;left:0;height:'+a+';width:'+a+';text-align:center">'+props2+D[i]+'</B></font></div>'); document.write('</div></div>'); document.write('<div id="Of" style="position:absolute;top:0px;left:0px"><div style="position:relative" mce_style="position:relative">'); for (i=0; i < n; i++) document.write('<div id="ieFace'+i+'" style="position:absolute;top:0px;left:0;height:'+a+';width:'+a+';text-align:center">'+props+Face[i]+'</B></font></div>'); document.write('</div></div>'); document.write('<div id="Oh" style="position:absolute;top:0px;left:0px"><div style="position:relative" mce_style="position:relative">'); for (i=0; i < H.length; i++) document.write('<div id="ieHours'+i+'" style="position:absolute;width:16px;height:16px;font-family:Arial;font-size:16px;color:'+hCol+';text-align:center;font-weight:bold">'+H[i]+'</div>'); document.write('</div></div>'); document.write('<div id="Om" style="position:absolute;top:0px;left:0px"><div style="position:relative" mce_style="position:relative">'); for (i=0; i < M.length; i++) document.write('<div id="ieMinutes'+i+'" style="position:absolute;width:16px;height:16px;font-family:Arial;font-size:16px;color:'+mCol+';text-align:center;font-weight:bold">'+M[i]+'</div>'); document.write('</div></div>'); document.write('<div id="Os" style="position:absolute;top:0px;left:0px"><div style="position:relative" mce_style="position:relative">'); for (i=0; i < S.length; i++) document.write('<div id="ieSeconds'+i+'" style="position:absolute;width:16px;height:16px;font-family:Arial;font-size:16px;color:'+sCol+';text-align:center;font-weight:bold">'+S[i]+'</div>'); document.write('</div></div>'); function Mouse(evnt){ ymouse = (evnt)?evnt.pageY+ClockFromMouseY-(window.pageYOffset):event.y+ClockFromMouseY; xmouse = (evnt)?evnt.pageX+ClockFromMouseX:event.x+ClockFromMouseX; } if(window.addEventListener) window.addEventListener("mousemove", Mouse, false); else document.body.onmousemove=Mouse; function ClockAndAssign(){ time = new Date (); secs = time.getSeconds(); sec = -1.57 + Math.PI * secs/30; mins = time.getMinutes(); min = -1.57 + Math.PI * mins/30; hr = time.getHours(); hrs = -1.57 + Math.PI * hr/6+Math.PI*parseInt(time.getMinutes())/360; document.getElementById('Ot').style.top=window.document.body.scrollTop; document.getElementById('Od').style.top=window.document.body.scrollTop; document.getElementById('Of').style.top=window.document.body.scrollTop; document.getElementById('Oh').style.top=window.document.body.scrollTop; document.getElementById('Om').style.top=window.document.body.scrollTop; document.getElementById('Os').style.top=window.document.body.scrollTop; for (i=0; i < n; i++){ var F=document.getElementById('ieFace'+i).style; F.top=y[i] + ClockHeight*Math.sin(-1.0471 + i*Split*Math.PI/180)+scrll; F.left=x[i] + ClockWidth*Math.cos(-1.0471 + i*Split*Math.PI/180); } for (i=0; i < H.length; i++){ var HL=document.getElementById('ieHours'+i).style; HL.top=y[i]+HandY+(i*HandHeight)*Math.sin(hrs)+scrll; HL.left=x[i]+HandX+(i*HandWidth)*Math.cos(hrs); } for (i=0; i < M.length; i++){ var ML=document.getElementById('ieMinutes'+i).style; ML.top=y[i]+HandY+(i*HandHeight)*Math.sin(min)+scrll; ML.left=x[i]+HandX+(i*HandWidth)*Math.cos(min); } for (i=0; i < S.length; i++){ var SL=document.getElementById('ieSeconds'+i).style; SL.top=y[i]+HandY+(i*HandHeight)*Math.sin(sec)+scrll; SL.left=x[i]+HandX+(i*HandWidth)*Math.cos(sec); } for (i=0; i < D.length; i++){ var DL=document.getElementById('ieDate'+i).style; DL.top=Dy[i] + ClockHeight*1.5*Math.sin(rigStep + i*Dsplit*Math.PI/180)+scrll; DL.left=Dx[i] + ClockWidth*1.5*Math.cos(rigStep + i*Dsplit*Math.PI/180); } for (i=0; i < T.length; i++){ var TL=document.getElementById('Text'+i).style; TL.top=Ty[i] + ClockHeight*2*Math.sin(currStep+i*Tsplit*Math.PI/180)+scrll; TL.left=Tx[i] + ClockWidth*2*Math.cos(currStep+i*Tsplit*Math.PI/180); } currStep-=step; rigStep+=rstep; } function Delay(){ scrll=(window.pageYOffset==null)?0:window.pageYOffset; Ty[0]=Math.round(TY[0]+=((ymouse)-TY[0])*speed); Tx[0]=Math.round(TX[0]+=((xmouse)-TX[0])*speed); for (i=1; i < T.length; i++){ Ty[i]=Math.round(TY[i]+=(Ty[i-1]-TY[i])*speed); Tx[i]=Math.round(TX[i]+=(Tx[i-1]-TX[i])*speed); } Dy[0]=Math.round(DY[0]+=((ymouse)-DY[0])*speed); Dx[0]=Math.round(DX[0]+=((xmouse)-DX[0])*speed); for (i=1; i < D.length; i++){ Dy[i]=Math.round(DY[i]+=(Dy[i-1]-DY[i])*speed); Dx[i]=Math.round(DX[i]+=(Dx[i-1]-DX[i])*speed); } y[0]=Math.round(Y[0]+=((ymouse)-Y[0])*speed); x[0]=Math.round(X[0]+=((xmouse)-X[0])*speed); for (i=1; i < n; i++){ y[i]=Math.round(Y[i]+=(y[i-1]-Y[i])*speed); x[i]=Math.round(X[i]+=(x[i-1]-X[i])*speed); }//以上为实际转动运行算法. ClockAndAssign(); setTimeout('Delay()',20); } window.onload=Delay; </SCRIPT>

你可能感兴趣的:(JavaScript,算法,Date,function,div,delay)