TShopping

標題: 滑鼠語法(時鐘跟隨) [打印本頁]

作者: woff    時間: 2008-6-1 16:25
標題: 滑鼠語法(時鐘跟隨)

  1. <!-- BEGIN Eric's Mouse-Clock CODE -->
  2. <SCRIPT language=javascript>
  3. dCol='8A78FF';//date colour.
  4. fCol='8A78FF';//face colour.
  5. sCol='8A78FF';//seconds colour.
  6. mCol='8A78FF';//minutes colour.
  7. hCol='8A78FF';//hours colour.
  8. ClockHeight=40;
  9. ClockWidth=40;
  10. ClockFromMouseY=0;
  11. ClockFromMouseX=100;

  12. //Alter nothing below! Alignments will be lost!

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

  155. <!-- END Mouse-Clock CODE the Code
  156. was design by Eric Chen!!!-->
複製代碼

作者: s2999306    時間: 2008-10-16 16:05
這個語法要貼在哪個後面阿。
作者: woff    時間: 2009-1-2 15:48
這是自己建一個網頁檔案
作者: vwypd    時間: 2012-7-29 00:50
好帖子,謝樓主
作者: chow2792    時間: 2012-7-29 00:53
我在努力中  
作者: msxee    時間: 2012-12-27 11:03
谢谢你的发言` 非常有意义




歡迎光臨 TShopping (http://www.tshopping.com.tw/) Powered by Discuz! X3.2