2008年8月29日

跟随鼠标的时钟

代码效果:跟随鼠标的时钟。

代码如下:


<!--将以下代码加入HTML的<Body></Body>之间--><br /><br /><script LANGUAGE="JavaScript1.2"><br />colors = new Array('330099','00ff00','ff00ff');<br />sCol = '800000'<br />mCol = '00FF00'<br />hCol = 'FF0000'<br />H = '***';<br />H = H.split('');<br />H = H.reverse();<br />M = '****';<br />M = M.split('');<br />M = M.reverse();<br />S = '*****';<br />S = S.split('');<br />S = S.reverse();<br />dots = 12;<br />var Ypos = 0,Xpos = 0,Ybase = 0,Xbase = 0;<br />var ay = 0, ax = 0, Ay = 0, Ax = 0, by = 0, bx = 0, By = 0, Bx = 0, cy<br />= 0, cx = 0, Cy = 0, Cx = 0, dy = 0, dx = 0, Dy = 0, Dx = 0;<br />count = 0;<br />count_a = 0;<br />move = 1;<br />ie4=document.all<br />ns = (document.layers)?1:0;<br /><br />viz = (document.layers)?'hide':'hidden';<br />if (ns) {<br />for (i = 0; i < dots; i++)<br />document.write('<layer name=nface'+i+' top=0 left=0 bgcolor=#000099 clip="0,0,3,3"></layer>');<br />for (i = 0; i < S.length; i++)<br />document.write('<layer name=nx'+i+' top=0 left=0 width=36 height=36><font face=Verdana size=2 color='+sCol+'><center>'+S[i]+'</center></font></layer>');<br />for (i = 0; i < M.length; i++)<br />document.write('<layer name=ny'+i+' top=0 left=0 width=36 height=36><font face=Verdana size=2 color='+mCol+'><center>'+M[i]+'</center></font></layer>');<br />for (i = 0; i < H.length; i++)<br />document.write('<layer name=nz'+i+' top=0 left=0 width=36 height=36><font face=Verdana size=2 color='+hCol+'><center>'+H[i]+'</center></font></layer>');<br />}<br />else if (ie4){<br />document.write('<div id="W" style="position:absolute;top:0px;left:0px"><div style="position:relative">');<br />for (i = 0; i < dots; i++) {<br />document.write('<div id="face" style="position:absolute;top:0px;left:0px;width:3px;height:3px;font-size:3px;background:#000099"></div>');<br />}<br />document.write('</div></div>');<br />document.write('<div id="X" style="position:absolute;top:0px;left:0px"><div style="position:relative">');<br />for (i = 0; i < S.length; i++) {<br />document.write('<div id="x" style="position:absolute;width:36px;height:36px;font-family:Verdana;font-size:12px;color:'+sCol+';text-align:center;padding-top:10px">'+S[i]+'</div>');<br />}<br />document.write('</div></div>')<br />document.write('<div id="Y" style="position:absolute;top:0px;left:0px"><div style="position:relative">');<br />for (i = 0; i < M.length; i++) {<br />document.write('<div id="y" style="position:absolute;width:36px;height:36px;font-family:Verdana;font-size:12px;color:'+mCol+';text-align:center;padding-top:10px">'+M[i]+'</div>');<br />}<br />document.write('</div></div>')<br />document.write('<div id="Z" style="position:absolute;top:0px;left:0px"><div style="position:relative">');<br />for (i = 0; i < H.length; i++) {<br />document.write('<div id="z" style="position:absolute;width:36px;height:36px;font-family:Verdana;font-size:12px;color:'+hCol+';text-align:center;padding-top:10px">'+H[i]+'</div>');<br />}<br />document.write('</div></div>');<br />}<br />if (ns) {<br />window.captureEvents(Event.MOUSEMOVE);<br />function nsMouse(evnt) {<br />Ypos = evnt.pageY + 100;<br />Xpos = evnt.pageX + 100;<br />}<br />window.onMouseMove = nsMouse;<br />}<br />else if (ie4){<br />function ieMouse() {<br />Ypos = event.y + 100;<br />Xpos = event.x + 100;<br />}<br />document.onmousemove = ieMouse;<br />}<br />function clock() {<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())<br />/ 360;<br />Ybase = 15;<br />Xbase = 15;<br /><br />if (ns) {<br />document.layers["nx"+0].visibility = viz;<br />document.layers["ny"+0].visibility = viz;<br />document.layers["nz"+0].visibility = viz;<br />for (i = 0; i < S.length; i++) {<br />document.layers["nx"+i].top = ay - 12 + (i * Ybase) * Math.sin(sec);<br />document.layers["nx"+i].left = ax - 12 + (i * Xbase) * Math.cos(sec);<br />}<br />for (i = 0; i < M.length; i++) {<br />document.layers["ny"+i].top = by - 12 + (i * Ybase) * Math.sin(min);<br />document.layers["ny"+i].left = bx - 12 + (i * Xbase) * Math.cos(min);<br />}<br />for (i = 0; i < H.length; i++) {<br />document.layers["nz"+i].top = cy - 12 + (i * Ybase) * Math.sin(hrs);<br />document.layers["nz"+i].left = cx - 12 + (i * Xbase) * Math.cos(hrs);<br />}<br />for (i = 0; i < dots; ++i) {<br />document.layers["nface"+i].top = dy - 2 + (70 *<br />Math.sin(-0.49+dots+i/1.9));<br />document.layers["nface"+i].left = dx + 4 + (70 *<br />Math.cos(-0.49+dots+i/1.9));<br /> }<br />}<br />else if (ie4) {<br />var scrll = document.body.scrollTop;<br />W.style.pixelTop = scrll;<br />X.style.pixelTop = scrll;<br />Y.style.pixelTop = scrll;<br />Z.style.pixelTop = scrll;<br />x[0].style.visibility=viz;<br />y[0].style.visibility = viz;<br />z[0].style.visibility = viz;<br />for (i = 0; i < S.length; i++) {<br />x[i].style.pixelTop = ay - 12 + (i * Ybase) * Math.sin(sec);<br />x[i].style.pixelLeft = ax - 12 + (i * Xbase) * Math.cos(sec);<br />}<br />for (i = 0; i < M.length; i++) {<br />y[i].style.pixelTop = by - 12 + (i * Ybase) * Math.sin(min);<br />y[i].style.pixelLeft = bx - 12 + (i * Xbase) * Math.cos(min);<br />}<br />for (i = 0; i < H.length; i++) {<br />z[i].style.pixelTop = cy - 12 + (i * Ybase) * Math.sin(hrs);<br />z[i].style.pixelLeft = cx - 12 + (i * Xbase) * Math.cos(hrs);<br />}<br />for (i = 0; i < dots; ++i) {<br />face[i].style.pixelTop = dy + 6 + (70 * Math.sin(-0.49 + dots + i /<br />1.9));<br />face[i].style.pixelLeft = dx + 4 + (70 * Math.cos(-0.49 + dots + i /<br />1.9));<br /> }<br /> }<br />}<br />function MouseFollow() {<br />ay = Math.round(Ay += ((Ypos) - Ay) * 4 / 15);<br />ax = Math.round(Ax += ((Xpos) - Ax) * 4 / 15);<br />by = Math.round(By += (ay - By) * 4 / 15);<br />bx = Math.round(Bx += (ax - Bx) * 4 / 15);<br />cy = Math.round(Cy += (by - Cy) * 4 / 15);<br />cx = Math.round(Cx += (bx - Cx) * 4 / 15);<br />dy = Math.round(Dy += (cy - Dy) * 4 / 15);<br />dx = Math.round(Dx += (cx - Dx) * 4 / 15);<br />clock();<br />setTimeout('MouseFollow()',10);<br />}<br />function StartAll() {<br />MouseFollow();<br />}<br />if (document.layers || document.all) window.onload = StartAll;<br />// End --><br /></script><br /><br />

没有评论: