Membuat Count Down Timer Javascript Jquery

Hari saya membuat Count Down Timer dari Javasript Jquery , logikanya simple , mengurangi variable dengan angka satu dan diulang tiap satu detik

Berikut source code kasus saya  :

<h4>Please Wait….<span class=”time”>5</span> seconds to Google.com</h4>

<script>
$(function(){

timer();

function timer()
{
setTimeout(function(){
var time_span = $(‘.time’).html();
var time = parseInt(time_span);
var t = time – 1;
if(t == 0)
{
window.location.href = “http://google.com&#8221;;
}else{

$(‘.time’).html(t);

timer();
}

},1000);
}
});
</script>

Iklan

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s