admin管理员组文章数量:1026925
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
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
Share Improve this question edited Mar 8, 2010 at 9:21 Will Vousden 33.4k9 gold badges88 silver badges97 bronze badges asked Mar 8, 2010 at 9:10 HulkHulk 34.2k65 gold badges150 silver badges217 bronze badges3 Answers
Reset to default 6Not 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..
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
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
Share Improve this question edited Mar 8, 2010 at 9:21 Will Vousden 33.4k9 gold badges88 silver badges97 bronze badges asked Mar 8, 2010 at 9:10 HulkHulk 34.2k65 gold badges150 silver badges217 bronze badges3 Answers
Reset to default 6Not 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..
本文标签: javascriptjquery timer implementationStack Overflow
版权声明:本文标题:javascript - jquery timer implementation - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745655560a2161579.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论