My countdown plugin in JQuery

<!–

Hello, this is a very simple plugin that do some countdown for you.You can send two parameter. First one is the time in seconds where the countdown start and second is a callback function that after complete the countdown what you want to do written in here.
As you can see i create a pop up box to notify that the countdown is just end.So alert will be shown to user after the countdown comes to an end.

–>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”&gt;
<html xmlns=”http://www.w3.org/1999/xhtml”&gt;
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>Untitled Document</title>
<script type=”text/javascript” src=”jquery.js”></script>
<script type=”text/javascript” src=”plugin2.js”></script>
<script type=”text/javascript”>
$(document).ready(function(){

$(‘#spa’).countdown(10,function(){

alert(‘End of countdown!’);
});

});
</script>
</head>

<body>
<span id=”spa”></span>
</body>
</html>

======================================================

plugin2.js

(function($){

$.fn.countdown = function(time,func)
{

start = time;
function count()
{
$(‘#spa’).text(start);
start -=1;
if(start == 0){
clearInterval(time_interval);
func.call(this);
}
}
time_interval = setInterval(count,1000);

}

})(jQuery)

Leave a comment