请高手给该js代码(电子时钟)添加注释,越详细越好!

sangyiutung 发布于 2013/08/02 20:43
阅读 201
收藏 0
特别是很多的常量的地方,请给予详细的解释。
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>无标题页</title>
<style type="text/css">
	.timst{position:absolute;width:2px;height:2px;font-size:2px;}
	.dts{position:absolute;top:0px;left:0px;width:30px;height:30px;font-family:Arial,Verdana;
	     font-size:10px;color:"+fCol+";text-align:center;padding-top:10px}
</style>
<script language="javascript" type="text/javascript">
    var fCol = "#000000";//表盘数字颜色
    var hCol = "#fbb907";//时针颜色
    var mCol = "#337408";//分针颜色
    var sCol = "#FF0000";//秒针颜色
    var H = "...";//时针样式
    var M = "....";//分针样式
    var S = ".....";//秒针样式
    var Ybase =8;
    var Xbase =8;
    var dots =12;
    var ns = 0;
    if(document.all){
        for (i = 1; i <= dots; i++) {
        	document.write("<div id='ieDigits' class='dts'>"+i+"</div>");
        }

        for (i = 0; i < M.length; i++) {
        	document.write("<div id='y' class='timst' style='background:"+mCol+"'></div>");
        }
        for (i = 0; i < H.length; i++) {
        	document.write("<div id='z' class='timst' style='background:"+hCol+"'></div>");
        }
        for (i = 0; i < S.length; i++) {
        	document.write("<div id='x' class='timst' style='background:"+sCol+"'></div>");
        }
    }
    
    function clock() {
        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;
        if (ns!=0) {
			Ypos = window.pageYOffset+window.innerHeight;
			Xpos = window.pageXOffset+window.innerWidth;
        }
        else {
			for (i=0; i < dots; ++i){
				ieDigits[i].style.pixelTop = Ypos - 15 + 40 * Math.sin(-0.49+dots+i/1.9);
				ieDigits[i].style.pixelLeft = Xpos - 14 + 40 * Math.cos(-0.49+dots+i/1.9);
        	}
			for (i=0; i < S.length; i++){
				x[i].style.pixelTop = Ypos + i * Ybase * Math.sin(sec);
				x[i].style.pixelLeft = Xpos + i * Xbase * Math.cos(sec);
			}
			for (i=0; i < M.length; i++){
				y[i].style.pixelTop = Ypos + i * Ybase * Math.sin(min);
				y[i].style.pixelLeft = Xpos + i * Xbase * Math.cos(min);
			}
			for (i=0; i < H.length; i++){
				z[i].style.pixelTop = Ypos + i * Ybase*Math.sin(hrs);
				z[i].style.pixelLeft = Xpos + i * Xbase*Math.cos(hrs);
			}
        }
        setTimeout("clock()", 50);
    }
    Ypos =  window.document.body.clientHeight /8;
    Xpos = window.document.body.clientWidth /8-20;
    window.onload = clock;
</script>

</head>
<body>
    <form id="form1">
    <div>
    
    </div>
    </form>
</body>
</html>
加载中
返回顶部
顶部