Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // billede som skal vises. F.eks. /images/image_2.jpg"
- $image = "image_2.jpg";
- // tidspunkt på dagen der tælles ned til
- $tidspunkt = "13:30:00";
- // sekunder fra $tidspunkt hvor der blot skal vises et billede
- $pause = 60;
- $nu = time();
- $today = strtotime(date("Y-m-d ".$tidspunkt));
- $addtime = ($today+$pause);
- $next = ($today+86400);
- $seconds = ($nu >= $addtime ? ($next-$nu) : ($nu > $today && $nu < $addtime ? 0 : ($today-$nu)));
- $p_seconds = ($addtime-$nu);
- $restart = ($p_seconds >= 0 && $p_seconds <= $pause ? $p_seconds : $pause);
- ?>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
- <html><head><title>Js/php countdown</title>
- <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
- <style type="text/css">
- .tid {
- font-family: arial, verdana;
- font-size: 0.9em;
- }
- .myimage {
- width: 160px;
- height: 230px;;
- }
- </style>
- <script type="text/javascript">
- function countd(allseconds) {
- var myimg = '<?php echo $image; ?>';
- var timediv = document.getElementById('timetext');
- if(timediv) {
- var oneM = 60;
- var oneH = (60*60);
- var Htime = Math.floor(allseconds/oneH);
- var Mtime = Math.floor((allseconds-(Htime*oneH))/oneM);
- var Stime = Math.floor(allseconds-(Htime*oneH)-(Mtime*oneM));
- timediv.firstChild.nodeValue=(Htime<10?'0'+Htime:Htime)+' ti '+(Mtime<10?'0'+Mtime:Mtime)+' mi '+(Stime<10?'0'+Stime:Stime)+' se';
- if(allseconds){
- setTimeout('countd('+(allseconds-1)+');',1000);
- }else{
- timediv.firstChild.nodeValue='';
- var newElement=document.createElement('img');
- newElement.setAttribute('src',myimg);
- newElement.setAttribute('class','myimage');
- timediv.appendChild(newElement);
- restart(<?php echo $restart; ?>);
- }
- }else{
- return false;
- }
- }
- function restart(tid) {
- if(tid) {
- setTimeout('restart('+(tid-1)+');',1000);
- }else{
- return location.reload(true);
- }
- }
- </script>
- </head>
- <body>
- <div class="tid" id="timetext"> </div>
- <script type="text/javascript">
- countd(<?php echo $seconds; ?>);
- </script>
- </body></html>
Advertisement
Add Comment
Please, Sign In to add comment