Mari Diskusi Javascript Countdown Disini

 
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
View Mode
Views:

663


Replies:0

Mari Diskusi Javascript Countdown Disini

paman/tante ini gimana ya script countdownnya kalau di refresh gx ngulang lagi,, jadi timer terus berjalan.

Script :
Spoiler :
Quote:<?PHP
include("./koneksi.php");

$sql = mysql_query("SELECT `waktu` FROM `beta`");
$data = mysql_fetch_array($sql);
$timer = $data['waktu'];

session_start();
if(isset($_SESSION["mulai_waktu"])){
$telah_berlalu = time() - $_SESSION["mulai_waktu"];
}
else {
$_SESSION["mulai_waktu"] = time();
$telah_berlalu = 0;
}
?>
<html>
<head>
<title>Test</title>
</head>
<body>
<div id="cntdwn" class="awesome"></div>


<script>
CountActive = true;
CountStepper = -1;
LeadingZero = true;
var secs = '<?php echo $timer ?>';
DisplayFormat = "Time Left : %%H%%:%%M%%:%%S%%";
FinishMessage = "Teks nya disini";

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

function CountBack(secs) {
if (secs < 0) {
document.getElementById("cntdwn").innerHTML = FinishMessage;
return;
}
DisplayStr = DisplayFormat.replace(/%%D%%/g, calcage(secs,86400,100000));
DisplayStr = DisplayStr.replace(/%%H%%/g, calcage(secs,3600,24));
DisplayStr = DisplayStr.replace(/%%M%%/g, calcage(secs,60,60));
DisplayStr = DisplayStr.replace(/%%S%%/g, calcage(secs,1,60));

var sisa_waktu = secs - <?php echo $telah_berlalu ?>;

document.getElementById("cntdwn").innerHTML = DisplayStr;
if (CountActive){
setTimeout("CountBack(" + (secs+CountStepper) + ")", SetTimeOutPeriod);
}
}

CountStepper = Math.ceil(CountStepper);
if (CountStepper == 0) CountActive = false;
var SetTimeOutPeriod = (Math.abs(CountStepper)-1)*1000 + 990;
CountBack(secs);

</script>
</body>
</html>

Untuk script di atas :
Countdown berhasil muncul

Masalah :
Bila di refresh, countdown mengulang dari awal. Seharusnya bila halaman di refersh, countdown masih tetap berjalan normal dan tidak mengulang dari awal
kampoeng