Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE HTML><head>
- <title><3 Sasha</title>
- <style id="sty" type="text/css">
- body{
- padding: 200px;
- }
- #countdown{
- width: 790px;
- text-align: center;
- margin: 0 auto;
- padding: 20px;
- border: thin solid;
- }
- span{
- display: inline-block;
- font-size: 30px;
- font-weight: bold;
- font-family: Courier New;
- padding: 0 14px;
- }
- #countdown_days:after{
- content: " d";
- }
- #countdown_hour:after{
- content: " h";
- }
- #countdown_min:after{
- content: " m";
- }
- #countdown_sec:after{
- content: " s";
- }
- </style>
- </head><body>
- <script id="scr" type="text/javascript">
- function merge(obj){
- for (var k in obj){
- this[k] = obj[k];
- }
- this['innerText'] = obj['textContent'] || '';
- return this;
- }
- var lastObj = {};
- var lastTag = '';
- function newElement(obj){
- var e = document.createElement(lastTag = (obj.tag || lastTag));
- merge.call(e, ( obj.tag ? (lastObj = obj) : merge.call(lastObj, obj) ) );
- setTimeout( function(){ (e.parent || document.body).appendChild(e); }, 1 );
- return e;
- }
- function randomColor(){
- var x = 0;
- for ( var i = 2; i >= 0; i-- ){
- x += Math.floor( 255^i * 255 * Math.random() );
- }
- return x.toString(16);
- }
- function Countdown(date){
- var el = newElement({
- id: 'countdown'
- ,tag: 'div'
- });
- var days_span = newElement({
- id: 'countdown_days'
- ,tag: 'span'
- ,parent: el
- });
- var hour_span = newElement({
- id: 'countdown_hour'
- });
- var min_span = newElement({
- id: 'countdown_min'
- });
- var sec_span = newElement({
- id: 'countdown_sec'
- });
- var time = 0;
- function sync(){
- var now = new Date();
- var then = new Date(date);
- time = Math.floor((then - now) / 1000);
- }
- var days, hour, min, sec, x;
- this.update = function(){
- if ( time % 600 == 0 ){
- sync();
- } else if ( --time <= 0 ){
- this.expire();
- }
- if ( (x = sec) != (sec = time / (1) % 60) )
- sec_span.innerHTML = Math.floor(sec);
- if ( (x = min) != (min = time / (60) % 60) )
- min_span.innerHTML = Math.floor(min);
- if ( (x = hour) != (hour = time / (60*60) % 24) )
- hour_span.innerHTML = Math.floor(hour);
- if ( (x = days) != (days = time / (60*60*24)) )
- days_span.innerHTML = Math.floor(days);
- }
- this.expire = function(){
- clearInterval(clk);
- // do stuff
- }
- var self = this;
- var clk = setInterval( function(){ self.update(); }, 1000 );
- this.update();
- }
- // var counter = new Countdown("Fri March 18 2011 15:00:00 GMT-0500");
- var counter = new Countdown("Feb 26 2011 11:20:00 GMT-0500");
- // Cleanup
- document.body.removeChild( document.getElementById('scr') );
- </script>
- </body></html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement