鸿新论坛

 找回密码
 快速注册

QQ登录

只需一步,快速开始

查看: 2884|回复: 6

[鼠标类特效] 非常有趣跟随鼠标移动的漂亮时钟

[复制链接]
发表于 2011-12-18 22:04:51 | 显示全部楼层 |阅读模式

非常有趣跟随鼠标移动的漂亮时钟

新窗口预览地址:https://www.hhxin.com/code/mouse/17005.html

代码如下:
  1. <SCRIPT language=JavaScript><!--
  2. dCol='0000FF';//date colour.
  3. fCol='0000FF';//face colour.
  4. sCol='0000FF';//seconds colour.
  5. mCol='0000FF';//minutes colour.
  6. hCol='0000FF';//hours colour.
  7. ClockHeight=40;
  8. ClockWidth=40;
  9. ClockFromMouseY=0;
  10. ClockFromMouseX=100;
  11. //Alter nothing below! Alignments will be lost!
  12. d=new Array("SUNDAY","MONDAY","TUESDAY","WEDNESDAY","THURSDAY","FRIDAY","SATURDAY");
  13. m=new Array("JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE","JULY","AUGUST","SEPTEMBER","OCTOBER","NOVEMBER","DECEMBER");
  14. date=new Date();
  15. day=date.getDate();
  16. year=date.getYear();
  17. if (year < 2000) year=year+1900;
  18. TodaysDate=" "+d[date.getDay()]+" "+day+" "+m[date.getMonth()]+" "+year;
  19. D=TodaysDate.split('');
  20. H='...';
  21. H=H.split('');
  22. M='....';
  23. M=M.split('');
  24. S='.....';
  25. S=S.split('');
  26. Face='1 2 3 4 5 6 7 8 9 10 11 12';
  27. font='Arial';
  28. size=1;
  29. speed=0.5;
  30. ns=(document.layers);
  31. ie=(document.all);
  32. Face=Face.split(' ');
  33. n=Face.length;
  34. a=size*10;
  35. ymouse=0;
  36. xmouse=0;
  37. scrll=0;
  38. props="<font face="+font+" size="+size+" color="+fCol+"><B>";
  39. props2="<font face="+font+" size="+size+" color="+dCol+"><B>";
  40. Split=360/n;
  41. Dsplit=360/D.length;
  42. HandHeight=ClockHeight/4.5
  43. HandWidth=ClockWidth/4.5
  44. HandY=-7;
  45. HandX=-2.5;
  46. scrll=0;
  47. step=0.06;
  48. currStep=0;
  49. y=new Array();x=new Array();Y=new Array();X=new Array();
  50. for (i=0; i < n; i++){y[i]=0;x[i]=0;Y[i]=0;X[i]=0}
  51. Dy=new Array();Dx=new Array();DY=new Array();DX=new Array();
  52. for (i=0; i < D.length; i++){Dy[i]=0;Dx[i]=0;DY[i]=0;DX[i]=0}
  53. if (ns){
  54. for (i=0; i < D.length; i++)
  55. document.write('<layer name="nsDate'+i+'" top=0 left=0 height='+a+' width='+a+'><center>'+props2+D[i]+'</font></center></layer>');
  56. for (i=0; i < n; i++)
  57. document.write('<layer name="nsFace'+i+'" top=0 left=0 height='+a+' width='+a+'><center>'+props+Face[i]+'</font></center></layer>');
  58. for (i=0; i < S.length; i++)
  59. 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>');
  60. for (i=0; i < M.length; i++)
  61. 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>');
  62. for (i=0; i < H.length; i++)
  63. 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>');
  64. }
  65. if (ie){
  66. document.write('<div id="Od" style="position:absolute;top:0px;left:0px"><div style="position:relative">');
  67. for (i=0; i < D.length; i++)
  68. document.write('<div id="ieDate" style="position:absolute;top:0px;left:0;height:'+a+';width:'+a+';text-align:center">'+props2+D[i]+'</B></font></div>');
  69. document.write('</div></div>');
  70. document.write('<div id="Of" style="position:absolute;top:0px;left:0px"><div style="position:relative">');
  71. for (i=0; i < n; i++)
  72. document.write('<div id="ieFace" style="position:absolute;top:0px;left:0;height:'+a+';width:'+a+';text-align:center">'+props+Face[i]+'</B></font></div>');
  73. document.write('</div></div>');
  74. document.write('<div id="Oh" style="position:absolute;top:0px;left:0px"><div style="position:relative">');
  75. for (i=0; i < H.length; i++)
  76. 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>');
  77. document.write('</div></div>');
  78. document.write('<div id="Om" style="position:absolute;top:0px;left:0px"><div style="position:relative">');
  79. for (i=0; i < M.length; i++)
  80. 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>');
  81. document.write('</div></div>')
  82. document.write('<div id="Os" style="position:absolute;top:0px;left:0px"><div style="position:relative">');
  83. for (i=0; i < S.length; i++)
  84. 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>');
  85. document.write('</div></div>')
  86. }
  87. (ns)?window.captureEvents(Event.MOUSEMOVE):0;
  88. function Mouse(evnt){
  89. ymouse = (ns)?evnt.pageY+ClockFromMouseY-(window.pageYOffset):event.y+ClockFromMouseY;
  90. xmouse = (ns)?evnt.pageX+ClockFromMouseX:event.x+ClockFromMouseX;
  91. }
  92. (ns)?window.onMouseMove=Mouse:document.onmousemove=Mouse;
  93. function ClockAndAssign(){
  94. time = new Date ();
  95. secs = time.getSeconds();
  96. sec = -1.57 + Math.PI * secs/30;
  97. mins = time.getMinutes();
  98. min = -1.57 + Math.PI * mins/30;
  99. hr = time.getHours();
  100. hrs = -1.575 + Math.PI * hr/6+Math.PI*parseInt(time.getMinutes())/360;
  101. if (ie){
  102. Od.style.top=window.document.body.scrollTop;
  103. Of.style.top=window.document.body.scrollTop;
  104. Oh.style.top=window.document.body.scrollTop;
  105. Om.style.top=window.document.body.scrollTop;
  106. Os.style.top=window.document.body.scrollTop;
  107. }
  108. for (i=0; i < n; i++){
  109. var F=(ns)?document.layers['nsFace'+i]:ieFace[i].style;
  110. F.top=y[i] + ClockHeight*Math.sin(-1.0471 + i*Split*Math.PI/180)+scrll;
  111. F.left=x[i] + ClockWidth*Math.cos(-1.0471 + i*Split*Math.PI/180);
  112. }
  113. for (i=0; i < H.length; i++){
  114. var HL=(ns)?document.layers['nsHours'+i]:ieHours[i].style;
  115. HL.top=y[i]+HandY+(i*HandHeight)*Math.sin(hrs)+scrll;
  116. HL.left=x[i]+HandX+(i*HandWidth)*Math.cos(hrs);
  117. }
  118. for (i=0; i < M.length; i++){
  119. var ML=(ns)?document.layers['nsMinutes'+i]:ieMinutes[i].style;
  120. ML.top=y[i]+HandY+(i*HandHeight)*Math.sin(min)+scrll;
  121. ML.left=x[i]+HandX+(i*HandWidth)*Math.cos(min);
  122. }
  123. for (i=0; i < S.length; i++){
  124. var SL=(ns)?document.layers['nsSeconds'+i]:ieSeconds[i].style;
  125. SL.top=y[i]+HandY+(i*HandHeight)*Math.sin(sec)+scrll;
  126. SL.left=x[i]+HandX+(i*HandWidth)*Math.cos(sec);
  127. }
  128. for (i=0; i < D.length; i++){
  129. var DL=(ns)?document.layers['nsDate'+i]:ieDate[i].style;
  130. DL.top=Dy[i] + ClockHeight*1.5*Math.sin(currStep+i*Dsplit*Math.PI/180)+scrll;
  131. DL.left=Dx[i] + ClockWidth*1.5*Math.cos(currStep+i*Dsplit*Math.PI/180);
  132. }
  133. currStep-=step;
  134. }
  135. function Delay(){
  136. scrll=(ns)?window.pageYOffset:0;
  137. Dy[0]=Math.round(DY[0]+=((ymouse)-DY[0])*speed);
  138. Dx[0]=Math.round(DX[0]+=((xmouse)-DX[0])*speed);
  139. for (i=1; i < D.length; i++){
  140. Dy[i]=Math.round(DY[i]+=(Dy[i-1]-DY[i])*speed);
  141. Dx[i]=Math.round(DX[i]+=(Dx[i-1]-DX[i])*speed);
  142. }
  143. y[0]=Math.round(Y[0]+=((ymouse)-Y[0])*speed);
  144. x[0]=Math.round(X[0]+=((xmouse)-X[0])*speed);
  145. for (i=1; i < n; i++){
  146. y[i]=Math.round(Y[i]+=(y[i-1]-Y[i])*speed);
  147. x[i]=Math.round(X[i]+=(x[i-1]-X[i])*speed);
  148. }
  149. ClockAndAssign();
  150. setTimeout('Delay()',40);
  151. }
  152. if (ns||ie)window.onload=Delay;
  153. // --></SCRIPT>
复制代码

您需要登录后才可以回帖 登录 | 快速注册

本版积分规则

粤ICP备13047937号-2

GMT+8, 2018-9-22 10:25 , Processed in 0.067384 second(s), 19 queries .

Powered by Discuz! X3.4

快速回复 返回顶部 返回列表