Countdown script hulp nodig

Status
Niet open voor verdere reacties.

Sietsko

Nieuwe gebruiker
Lid geworden
18 mei 2011
Berichten
1
Ik heb een script en dat werkt op zich allemaal goed, maar ik wil het graag uitbreiden met 2 opties.

Het is de bedoeling als de tijd <0 = dat de this.FinishMessage wordt geprint op de plaats van de teller.

Ook wou ik graag de achtergrond en voorgrondkleur in kunnen stellen.

Wie kan mij helpen, ik heb wel enige kennis van PHP, maar geen kennis van Javascript, dus enige hulp is zeer welkom.

Hieronder het script dat ik gebruik:

[js]
<script language="javascript">
function countdown(obj)
{
this.obj = obj;
this.Div = "clock";
this.TargetDate = "05/17/2011 22:00:00";
this.DisplayFormat = "%%H%%:%%M%%:%%S%%";
this.CountActive = true;

this.FinishMessage = "Aangevallen !!";
this.BackColor = "red";
this.ForeColor = "white";

this.DisplayStr;
this.Calcage = cd_Calcage;
this.CountBack = cd_CountBack;
this.Setup = cd_Setup;
}


function cd_Calcage(secs, num1, num2)
{
s = ((Math.floor(secs/num1))%num2).toString();
if (s.length < 2) s = "0" + s;
return (s);
}


function cd_CountBack(secs)
{

this.DisplayStr = this.DisplayFormat.replace(/%%D%%/g, this.Calcage(secs,86400,100000));
this.DisplayStr = this.DisplayStr.replace(/%%H%%/g, this.Calcage(secs,3600,24));
this.DisplayStr = this.DisplayStr.replace(/%%M%%/g, this.Calcage(secs,60,60));
this.DisplayStr = this.DisplayStr.replace(/%%S%%/g, this.Calcage(secs,1,60));

document.getElementById(this.Div).innerHTML = this.DisplayStr;
if (this.CountActive) setTimeout(this.obj +".CountBack(" + (secs-1) + ")", 990);
}


function cd_Setup()
{
var dthen = new Date(this.TargetDate);
var dnow = new Date();
ddiff = new Date(dthen-dnow);
gsecs = Math.floor(ddiff.valueOf()/1000);
this.CountBack(gsecs);
}

</script>
[/js]


En op de volgende manier word het in beeld gebracht.

[js]
<script language="javascript">
var cd<?php echo $k; ?> = new countdown('cd<?php echo $k; ?>');
cd<?php echo $k; ?>.Div = "clock<?php echo $k; ?>";
cd<?php echo $k; ?>.TargetDate = "<?php echo $maand."/".$dag."/".$jaar." ".$hour.":".$minute.":".$second; ?>";
cd<?php echo $k; ?>.DisplayFormat = "%%H%%:%%M%%:%%S%%";
</script>

<div id="clockwrapper"><div id="clock<?php echo $k; ?>">[clock<?php echo $k; ?>]</div></div>

<script language="javascript">
<!--
cd<?php echo $k; ?>.Setup();
//-->
</script>
[/js]

Wie kan mij dus helpen om het werkend te krijgen ?

Sietsko
 
Laatst bewerkt:
Code:
<?php
 $k= 1;
?>
<html>
<head>
   <script type="text/javascript"><!--
	var cd<?php echo $k; ?>;
	function countdown(obj)
    {
        this.obj            = obj;
        this.Div            = "clock";
        this.TargetDate     = "05/17/2011 22:00:00";
        this.DisplayFormat  = "%%H%%:%%M%%:%%S%%";
        this.CountActive    = true;
 
        this.FinishMessage  = "Aangevallen !!";
        this.BackColor      = "red";
        this.ForeColor      = "white";
    
        this.DisplayStr;
        this.Calcage        = cd_Calcage;
        this.CountBack      = cd_CountBack;
        this.Setup          = cd_Setup;
		return this;
    }
 
 
    function cd_Calcage(secs, num1, num2)
    {
        s = ((Math.floor(secs/num1))%num2).toString();
        if (s.length < 2) s = "0" + s;
        return (s);
    }
 
 
    function cd_CountBack(secs)
    {
  
        this.DisplayStr = this.DisplayFormat.replace(/%%D%%/g,  this.Calcage(secs,86400,100000));
        this.DisplayStr = this.DisplayStr.replace(/%%H%%/g,     this.Calcage(secs,3600,24));
        this.DisplayStr = this.DisplayStr.replace(/%%M%%/g,     this.Calcage(secs,60,60));
        this.DisplayStr = this.DisplayStr.replace(/%%S%%/g,     this.Calcage(secs,1,60));
 
            document.getElementById(this.Div).innerHTML = this.DisplayStr;
        if (this.CountActive) setTimeout(this.obj +".CountBack(" + (secs-1) + ")", 990);
    }
 
 
    function cd_Setup()
    {
        var dthen   = new Date(this.TargetDate);
        var dnow    = new Date();
        ddiff       = new Date(dthen-dnow);
        gsecs       = Math.floor(ddiff.valueOf()/1000);
        this.CountBack(gsecs);
    }
	
	function startApp() {
	<?php
		$maand = 7;
		$dag = 26;
		$jaar = 2011;
		$hour = 6;
		$minute = 0;
		$second = 0;
	?>
		cd<?php echo $k; ?> = new countdown('cd<?php echo $k; ?>');
       cd<?php echo $k; ?>.Div         = "clock<?php echo $k; ?>";
       cd<?php echo $k; ?>.TargetDate      = "<?php echo $maand."/".$dag."/".$jaar." ".$hour.":".$minute.":".$second; ?>";
       cd<?php echo $k; ?>.DisplayFormat   = "%%H%%:%%M%%:%%S%%";
		cd<?php echo $k; ?>.Setup();	
	}
	--></script>
</head>

<body onload="startApp();">
<div id="clockwrapper"><div id="clock<?php echo $k; ?>">[clock<?php echo $k; ?>]</div></div>
</body>
</html>
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan