回复 21# yu2n
http://7i7hsj.com1.z0.glb.clouddn.com/ColorTimer1.html
你好。非常感谢。请教2个小问题。
1、win7 64系统,IE9 浏览器。这个网页源代码,保存成1.hta。为啥不显示:星期?
2、winxp系统,IE8浏览器。弹出错误提示窗口。- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <HTA:APPLICATION ID="screen"
- APPLICATIONNAME="myApp1"
- contextMenu ="no"
- BORDER="none"
- innerBorder="no"
- SHOWINTASKBAR="yes"
- SINGLEINSTANCE="yes"
- SYSMENU="no"
- VERSION="1.0"
- WINDOWSTATE="maximize"
- ICON="taskmgr.exe"
- />
- <html lang="cn">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>Timer & Color</title>
- <script language="JavaScript" type="text/javascript">
- /**
- * HSL颜色值转换为RGB.
- * 换算公式改编自 http://en.wikipedia.org/wiki/HSL_color_space.
- * h, s, 和 l 设定在 [0, 1] 之间
- * 返回的 r, g, 和 b 在 [0, 255]之间
- *
- * @param Number h 色相
- * @param Number s 饱和度
- * @param Number l 亮度
- * @return Array RGB色值数值
- */
- function hslToRgb(h, s, l){
- var r, g, b;
-
- if(s == 0){
- r = g = b = l; // achromatic
- }else{
- var hue2rgb = function hue2rgb(p, q, t){
- if(t < 0) t += 1;
- if(t > 1) t -= 1;
- if(t < 1/6) return p + (q - p) * 6 * t;
- if(t < 1/2) return q;
- if(t < 2/3) return p + (q - p) * (2/3 - t) * 6;
- return p;
- }
-
- var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
- var p = 2 * l - q;
- r = hue2rgb(p, q, h + 1/3);
- g = hue2rgb(p, q, h);
- b = hue2rgb(p, q, h - 1/3);
- }
-
- return [Math.round(r * 255), Math.round(g * 255), Math.round(b * 255)];
- }
-
-
- /**
- * RGB 颜色值转换为 HSL.
- * 转换公式参考自 http://en.wikipedia.org/wiki/HSL_color_space.
- * r, g, 和 b 需要在 [0, 255] 范围内
- * 返回的 h, s, 和 l 在 [0, 1] 之间
- *
- * @param Number r 红色色值
- * @param Number g 绿色色值
- * @param Number b 蓝色色值
- * @return Array HSL各值数组
- */
- function rgbToHsl(r, g, b){
- r /= 255, g /= 255, b /= 255;
- var max = Math.max(r, g, b), min = Math.min(r, g, b);
- var h, s, l = (max + min) / 2;
-
- if(max == min){
- h = s = 0; // achromatic
- }else{
- var d = max - min;
- s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
- switch(max){
- case r: h = (g - b) / d + (g < b ? 6 : 0); break;
- case g: h = (b - r) / d + 2; break;
- case b: h = (r - g) / d + 4; break;
- }
- h /= 6;
- }
-
- return [h, s, l];
- }
-
- //RGB转HEX
- function rgb2hex(rgb) {
- if (rgb.charAt(0) == '#') return rgb;
- function zero_fill_hex(num, digits) {
- var s = num.toString(16);
- while (s.length < digits) s = "0" + s;
- return s;
- };
- if (/rgb\(\d+, \d+, \d+\)/.test(rgb)) {
- var ds = rgb.match(/\d+/g);;
- var decimal = Number(ds[0]) * 65536 + Number(ds[1]) * 256 + Number(ds[2]);
- return "#" + zero_fill_hex(decimal, 6);
- };
- }
-
- //改变色调
- var HueSign = []; //色调符号
- function changColor(obj,uuid,type,step) {
- if (!HueSign[uuid]) HueSign[uuid] = 1;
- var rgb = obj.style[type];
- var hex = (rgb2hex(rgb)).substring(1);
- var r = parseInt("0x" + hex.substr(0,2));
- var g = parseInt("0x" + hex.substr(2,2));
- var b = parseInt("0x" + hex.substr(4,2));
- var hsl = rgbToHsl(r,g,b);
- var h = Math.round(hsl[0] * 2400)/10;
- var s = Math.round(hsl[1] * 2400)/10;
- var l = Math.round(hsl[2] * 2400)/10;
- h = h + HueSign[uuid] * step * 1; //修改色调
- if (h <= 0 || h >= 240) HueSign[uuid] = -1 * HueSign[uuid];
- if (h <= 0) h = 0;
- if (h >= 240) h = 240;
- var rgb = hslToRgb(h/240, s/240, l/240);
- hex = rgb2hex('rgb(' + rgb.join(', ') + ')');
- obj.style[type] = hex;
- return(true);
- }
- </script>
- <script language="JavaScript" type="text/javascript">
- //设置字体大小位置
- var LastSize = []; //记录最后的大小
- function changeFontSize() {
-
- var w = document.documentElement.clientWidth;
- var h = document.documentElement.clientHeight;
- if ((LastSize['Width'] != w) || (LastSize['Height'] != h)) {
- LastSize['Width'] = w;
- LastSize['Height'] = h;
-
- var size = w/100;
- document.getElementById("curtime").style.fontSize = "" + parseInt(size * 35) + "px";
- document.getElementById("cursec").style.fontSize = "" + parseInt(size * 10) + "px";
- document.getElementById("curdate").style.fontSize = "" + parseInt(size * 15) + "px";
- document.getElementById("curweek").style.fontSize = "" + parseInt(size * 15) + "px";
-
- var center = document.getElementById("center");
- center.style.left = (w - center.clientWidth)/2 + "px";
- center.style.top = (h - center.clientHeight)/2 + "px";
- }
- }
-
- //显示时间
- function SetTimeText() {
- var dt1=new Date();
- document.getElementById("curtime").innerHTML = dt1.getHours() + ":" + ("00" + dt1.getMinutes()).slice(-2);
- document.getElementById("cursec").innerHTML = ("00" + dt1.getSeconds()).slice(-2);
- document.getElementById("curdate").innerHTML= dt1.getMonth() + "-" + dt1.getDate();
- document.getElementById("curweek").innerHTML = "周" + "日一二三四五六".substr(dt1.getDay(), 1);
- }
-
- window.onload = function(){
-
- //关闭窗口(HTA)
- function closeWindow() {
- try {
- var Shell = new ActiveXObject("Shell.Application");
- Shell = null;
- window.close();
- } catch(e) {}
- }
- document.body.onclick = function(){ closeWindow(); };
- document.body.onkeyup = function(){ closeWindow(); };
-
- //显示时间
- SetTimeText();
- changeFontSize();
- setInterval(function(){
- SetTimeText();
- changeFontSize();
- }, 500);
-
- //修改颜色
- document.body.style['backgroundColor'] = '#336699';
- document.body.style['color'] = '#FFFFFF';
- setInterval(function(){
- //changColor(document.body, 'body::color', 'color', 1);
- changColor(document.body, 'body::backgroundColor', 'backgroundColor', 1);
- }, 50);
- };
-
-
- </script>
- <style type="text/css">
- #center {position: absolute; }
- #center strong {display: inline; padding: 2%; font-family:SimHei,"Microsoft YaHei","Microsoft JhengHei",DFKai-SB,SimSun;}
- </style>
- </head>
- <body scroll="no">
- <div id='center'>
- <strong id="curtime" /></strong><strong id="cursec" /></strong>
- <br/>
- <center><strong id="curdate" /></strong><strong id="curweek" /></strong></center>
- </div>
- </body>
- </html>
复制代码
|