A pop-up clock (tested in firefox and safari, but should work in ie8 as well)
javascript: var w = window.open(“”, “_blank”, “width=600,height=600″); var pi = 3.1415927; var d = w.document; for(var i = 1; i<= 12; i ++) { var div = d.createElement(“div”); var radian = i * pi *2 / 12 – pi / 2; var x = Math.cos(radian) * 40 + 50; var y = Math.sin(radian) * 40 + 50; div.style.width = “100px”; div.style.position = “absolute”; div.style.top = y + “%”; div.style.left = x + “%”; div.style.marginLeft = “-35px”; div.style.marginTop = “-10px”; div.style.textAlign = “center”; t =d.createTextNode(i); div.style.fontSize = “40pt”; div.appendChild(t); d.body.appendChild(div); } var seconds = createHands(d, “green”); var minutes = createHands(d, “blue”); var hours = createHands(d, “red”); tick(); function tick() { setTimeout(“tick()”, 1000); var time = new Date(); var second = time.getSeconds(); var minute = time.getMinutes()+ second / 60; var hour = time.getHours() + minute / 60; positionHand(seconds, second, 60, 3.5); positionHand(minutes, minute,60, 3); positionHand(hours, hour, 12, 2.5); } function positionHand(dots, value, max, size) { for(var i = 0; i < 10; i ++) {var radian = value * pi * 2 / max – pi / 2; var x = Math.cos(radian) *size * i + 50; var y = Math.sin(radian) * size * i + 50; var dot =dots[i]; dot.style.top = y + “%”; dot.style.left = x + “%”; } } function createHands(d, color) { var dots = new Array(); for(var i =0; i < 10; i ++) { dots[i] = document.createElement(“span”); var dot =dots[i]; dot.style.color = color; dot.style.position = “absolute”; dot.style.fontSize = “30px”; var t = document.createTextNode(“@”); dot.appendChild(t); d.body.appendChild(dot); } return dots; }
Post a Comment