1.466 views
Al opgelost.
<?php
$aftellers = array(
array('goud', 500),
array('klei', 350),
array('hout', 123)
);
$aftellers_js = json_encode($aftellers); // $aftellers_js is een string die javascript kan lezen.
?>
<html>
<head>
<style>
#goud {
background-color: #FFF82D;
margin: 10px;
}
#klei {
background-color: #FF9E66;
margin: 10px;
}
#hout {
background-color: #542E15;
margin: 10px;
}
</style>
</head>
<body>
<div id="goud"></div>
<div id="klei"></div>
<div id="hout"></div>
<script type="text/javascript">
var aftellers = <?php echo $aftellers_js; ?>;
countdown(0); // trigger de goud-timer
countdown(1); // trigger de klei-timer
countdown(2);
function countdown(index) {
document.getElementById(aftellers[index][0]).innerHTML = aftellers[index][1]--;
setTimeout('countdown(' + index + ')', 1000);
}
</script>
</body>
</html>