Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE HTML><head>
  2.     <title><3 Sasha</title>
  3.     <style id="sty" type="text/css">       
  4.         body{
  5.             padding: 200px;
  6.         }
  7.        
  8.         #countdown{
  9.             width: 790px;
  10.             text-align: center;
  11.             margin: 0 auto;
  12.             padding: 20px;
  13.             border: thin solid;
  14.         }
  15.    
  16.         span{
  17.             display: inline-block;
  18.             font-size: 30px;
  19.             font-weight: bold;
  20.             font-family: Courier New;
  21.             padding: 0 14px;
  22.         }
  23.  
  24.         #countdown_days:after{
  25.             content: " d";
  26.         }
  27.         #countdown_hour:after{
  28.             content: " h";
  29.         }
  30.         #countdown_min:after{
  31.             content: " m";
  32.         }
  33.         #countdown_sec:after{
  34.             content: " s";
  35.         }
  36.     </style>
  37. </head><body>
  38.     <script id="scr" type="text/javascript">
  39.         function merge(obj){
  40.             for (var k in obj){
  41.                 this[k] = obj[k];
  42.             }
  43.             this['innerText'] = obj['textContent'] || '';
  44.             return this;
  45.         }
  46.        
  47.         var lastObj = {};
  48.         var lastTag = '';
  49.         function newElement(obj){
  50.             var e = document.createElement(lastTag = (obj.tag || lastTag));
  51.             merge.call(e, ( obj.tag ? (lastObj = obj) : merge.call(lastObj, obj) ) );
  52.             setTimeout( function(){ (e.parent || document.body).appendChild(e); }, 1 );
  53.             return e;
  54.         }
  55.        
  56.         function randomColor(){
  57.             var x = 0;
  58.             for ( var i = 2; i >= 0; i-- ){
  59.                 x += Math.floor( 255^i * 255 * Math.random() );
  60.             }
  61.             return x.toString(16);
  62.         }
  63.    
  64.         function Countdown(date){
  65.             var el = newElement({
  66.                     id: 'countdown'
  67.                     ,tag: 'div'
  68.             });
  69.             var days_span =  newElement({
  70.                     id: 'countdown_days'
  71.                     ,tag: 'span'
  72.                     ,parent: el
  73.             });
  74.             var hour_span =  newElement({
  75.                     id: 'countdown_hour'
  76.             });
  77.             var min_span =  newElement({
  78.                     id: 'countdown_min'
  79.             });
  80.             var sec_span =  newElement({
  81.                     id: 'countdown_sec'
  82.             });
  83.            
  84.             var time = 0;
  85.             function sync(){
  86.                 var now = new Date();
  87.                 var then = new Date(date);
  88.                 time = Math.floor((then - now) / 1000);
  89.             }
  90.            
  91.             var days, hour, min, sec, x;
  92.             this.update = function(){
  93.                 if (  time % 600 == 0 ){
  94.                     sync();
  95.                 } else if ( --time <= 0 ){
  96.                     this.expire();
  97.                 }
  98.                 if ( (x = sec) != (sec = time / (1) % 60) )
  99.                     sec_span.innerHTML = Math.floor(sec);
  100.                 if ( (x = min) != (min = time / (60) % 60) )
  101.                     min_span.innerHTML = Math.floor(min);
  102.                 if ( (x = hour) != (hour = time / (60*60) % 24) )
  103.                     hour_span.innerHTML = Math.floor(hour);
  104.                 if ( (x = days) != (days = time / (60*60*24)) )
  105.                     days_span.innerHTML = Math.floor(days);
  106.             }
  107.            
  108.             this.expire = function(){
  109.                 clearInterval(clk);
  110.                 // do stuff
  111.             }
  112.            
  113.             var self = this;
  114.             var clk = setInterval( function(){ self.update(); }, 1000 );
  115.             this.update();
  116.         }
  117.        
  118.         // var counter = new Countdown("Fri March 18 2011 15:00:00 GMT-0500");
  119.         var counter = new Countdown("Feb 26 2011 11:20:00 GMT-0500");
  120.        
  121.         // Cleanup
  122.         document.body.removeChild( document.getElementById('scr') );
  123.     </script>
  124.    
  125. </body></html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement