Guest User

Untitled

a guest
Dec 22nd, 2010
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. // billede som skal vises. F.eks. /images/image_2.jpg"
  3. $image = "image_2.jpg";
  4.  
  5. // tidspunkt på dagen der tælles ned til
  6. $tidspunkt = "13:30:00";
  7.  
  8. // sekunder fra $tidspunkt hvor der blot skal vises et billede
  9. $pause = 60;
  10.  
  11. $nu = time();
  12. $today = strtotime(date("Y-m-d ".$tidspunkt));
  13. $addtime = ($today+$pause);
  14.  
  15. $next = ($today+86400);
  16.  
  17. $seconds = ($nu >= $addtime ? ($next-$nu) : ($nu > $today && $nu < $addtime ? 0 : ($today-$nu)));
  18.  
  19. $p_seconds = ($addtime-$nu);
  20. $restart = ($p_seconds >= 0 && $p_seconds <= $pause ? $p_seconds : $pause);
  21.  
  22. ?>
  23. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  24.  
  25. <html><head><title>Js/php countdown</title>
  26.  
  27. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
  28.  
  29. <style type="text/css">
  30.  
  31. .tid {
  32.     font-family: arial, verdana;
  33.     font-size: 0.9em;
  34.     }
  35.  
  36. .myimage {
  37.     width: 160px;
  38.     height: 230px;;
  39.         }
  40.  
  41. </style>
  42.  
  43. <script type="text/javascript">
  44.  
  45. function countd(allseconds) {
  46.  
  47. var myimg = '<?php echo $image; ?>';
  48. var timediv = document.getElementById('timetext');
  49.  
  50.     if(timediv) {
  51.     var oneM = 60;
  52.     var oneH = (60*60);
  53.     var Htime = Math.floor(allseconds/oneH);
  54.     var Mtime = Math.floor((allseconds-(Htime*oneH))/oneM);
  55.     var Stime = Math.floor(allseconds-(Htime*oneH)-(Mtime*oneM));
  56.  
  57.     timediv.firstChild.nodeValue=(Htime<10?'0'+Htime:Htime)+' ti '+(Mtime<10?'0'+Mtime:Mtime)+' mi '+(Stime<10?'0'+Stime:Stime)+' se';
  58.  
  59.         if(allseconds){
  60.  
  61.         setTimeout('countd('+(allseconds-1)+');',1000);
  62.  
  63.         }else{
  64.  
  65.         timediv.firstChild.nodeValue='';
  66.  
  67.         var newElement=document.createElement('img');
  68.         newElement.setAttribute('src',myimg);
  69.         newElement.setAttribute('class','myimage');
  70.         timediv.appendChild(newElement);
  71.         restart(<?php echo $restart; ?>);
  72.  
  73.         }
  74.  
  75.     }else{
  76.  
  77.     return false;
  78.  
  79.     }
  80.  
  81. }
  82.  
  83. function restart(tid) {
  84.  
  85.     if(tid) {
  86.     setTimeout('restart('+(tid-1)+');',1000);
  87.     }else{
  88.     return location.reload(true);
  89.     }
  90. }
  91.  
  92. </script>
  93.  
  94. </head>
  95.  
  96. <body>
  97.  
  98. <div class="tid" id="timetext">&nbsp;</div>
  99.  
  100. <script type="text/javascript">
  101. countd(<?php echo $seconds; ?>);
  102. </script>
  103.  
  104. </body></html>
Advertisement
Add Comment
Please, Sign In to add comment