开发者

jquery timer implementation

All,

Is there a jQuery timer which can start a timer for 20 minutes and display time elapsed? Please point me to a small code for it.

var austDay = new getTime(开发者_开发知识库);
austDay = new getSeconds(austDay);
var duration = 1200;
duration +=  austDay;

Thanks


Not sure about a jQuery solution, but it's quite simple to do anyway:

var elapsed = 0;
var interval;
var total = 60 * 20; // 20 mins in seconds

function showElapsedTime()
{
    if(elapsed < total)
    {
        elapsed += 1;

        // If you want you can convert the seconds elapsed to minutes and seconds
        // here before you display them

        $('#elapsed').html(elapsed);
    }
    else
    {
        clearInterval(interval);
        alert('Done');
    }
}

$(function(){
    interval = setInterval(showElapsedTime, 1000);
});

Where #elapsed is a div or span element that you want to show the elapsed time in.

There are quite a few timer plugins, but they are all just abstractions of setTimeout and setInterval anyway, and I'm not sure they're really much simpler to use.


Here is an example using the jQuery Timers plugin. You can change it to suit your needs.

$("#start").click(function() {
    $("#example_2").everyTime(1000, 'timer2', function(i) {
        $(this).text(i);
    }, 15);
});

$("#stop").click(function() {
    $("#example_2").stopTime('timer2');
});


Are you searching for a plugin like timeX?

Maybe this is what you can use..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜