Minggu, 28 Juni 2015

Script Countdown (pure javaScript)




<span id="countdown"></span>
<script type="text/javascript">
    // set the date we're counting down to
    var targetDate = new Date("Jul 27, 2015").getTime();

    // variables for time units
    var days, hours, minutes, seconds;

    // get tag element
    var countdown = document.getElementById("countdown");

    // update the tag with id "countdown" every 1 second
    setInterval(function () {

        // find the amount of "seconds" between now and target
        var currentDate = new Date().getTime();
        var secondsLeft = (targetDate - currentDate) / 1000;

        // do some time calculations
        days = parseInt(secondsLeft / 86400);
        secondsLeft = secondsLeft % 86400;

        hours = parseInt(secondsLeft / 3600);
        secondsLeft = secondsLeft % 3600;

        minutes = parseInt(secondsLeft / 60);
        seconds = parseInt(secondsLeft % 60);

        // format countdown string + set tag value
        countdown.innerHTML = "<h1>" + days + " hari, " + hours + " jam, " + minutes + " menit, " + seconds + " detik</h1>";

    }, 1000);
</script> 

 Download aplikasi android Muhammad Zaini DI SINI

Tidak ada komentar:

Posting Komentar