Created
August 4, 2013 14:27
-
-
Save un33k/6150494 to your computer and use it in GitHub Desktop.
Quick way of creating a nice "live" clock in JS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* **************************** */ | |
/* Timezone */ | |
/* **************************** */ | |
.tz_date_time .tz_circle { | |
position: relative; | |
width: 92px; | |
height: 92px; | |
padding: 1px 2px 11px 2px; | |
} | |
.tz_date_time .tz_face { | |
width: 100%; | |
height: 100%; | |
border: 5px solid black; | |
border-radius: 50%; | |
position: relative; | |
} | |
.tz_date_time #tz_dot { | |
width: 0%; | |
height: 0%; | |
border: 5px solid black; | |
border-radius: 50%; | |
position: absolute; | |
top: 45%; | |
left: 44%; | |
} | |
.tz_date_time #tz_hour { | |
width: 0; | |
height: 0; | |
position: absolute; | |
top: 50%; | |
left: 50%; | |
margin: -5px 0 -5px -25%; | |
padding: 5px 0 5px 25%; | |
background: black; | |
-webkit-transform-origin: 100% 50%; | |
-moz-transform-origin: 100% 50%; | |
-ms-transform-origin: 100% 50%; | |
transform-origin: 100% 50%; | |
border-radius: 5px 0 0 5px; | |
} | |
.tz_date_time #tz_minute { | |
width: 0; | |
height: 0; | |
position: absolute; | |
top: 50%; | |
left: 50%; | |
margin: -45% -3px 0; | |
padding: 47% 4px 0; | |
background: black; | |
-webkit-transform-origin: 50% 100%; | |
-moz-transform-origin: 50% 100%; | |
-ms-transform-origin: 50% 100%; | |
transform-origin: 50% 100%; | |
border-radius: 5px 5px 0 0; | |
} | |
.tz_date_time #tz_second { | |
width: 0; | |
height: 0; | |
position: absolute; | |
top: 50%; | |
left: 50%; | |
margin: -40% -1px 0 0; | |
padding: 40% 1px 0; | |
background: black; | |
-webkit-transform-origin: 50% 100%; | |
-moz-transform-origin: 50% 100%; | |
-ms-transform-origin: 50% 100%; | |
transform-origin: 50% 100%; | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<body> | |
<span class="tz_date_time"> | |
<div class="tz_circle"> | |
<div class="tz_face"> | |
<div id="tz_dot"></div> | |
<div id="tz_hour"></div> | |
<div id="tz_minute"></div> | |
<div id="tz_second"></div> | |
</div> | |
</div> | |
</span> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
function tick_away(){ | |
var now = new Date(); | |
var second = now.getSeconds() * 6; | |
var minute = now.getMinutes() * 6 + second / 60; | |
var hour = ((now.getHours() % 12) / 12) * 360 + 90 + minute / 12; | |
$('#tz_hour').css("transform", "rotate(" + hour + "deg)"); | |
$('#tz_minute').css("transform", "rotate(" + minute + "deg)"); | |
$('#tz_second').css("transform", "rotate(" + second + "deg)"); | |
} | |
function tick_update () { | |
tick_away(); | |
setTimeout(tick_update, 1000); | |
} | |
// debugger; | |
tick_update(); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment