admin管理员组文章数量:1429399
I found this neat countdown timer and I was curious if someone could help with a few changes to it.
- Start on the click of a button.
- Where would I place an AJAX call function to a PHP file for when the timer hits 0?
- Repeat when it is finished.
The timer I found is here: /
var countdown = $("#countdown").countdown360({
radius: 60,
seconds: 20,
label: ['sec', 'secs'],
fontColor: '#FFFFFF',
autostart: false,
onComplete: function () {
console.log('done');
}
});
countdown.start();
$('#countdown').click(function() {
countdown.extendTimer(2);
});
Thanks in advance for any help given.
I found this neat countdown timer and I was curious if someone could help with a few changes to it.
- Start on the click of a button.
- Where would I place an AJAX call function to a PHP file for when the timer hits 0?
- Repeat when it is finished.
The timer I found is here: http://jsfiddle/johnschult/gs3WY/
var countdown = $("#countdown").countdown360({
radius: 60,
seconds: 20,
label: ['sec', 'secs'],
fontColor: '#FFFFFF',
autostart: false,
onComplete: function () {
console.log('done');
}
});
countdown.start();
$('#countdown').click(function() {
countdown.extendTimer(2);
});
Thanks in advance for any help given.
Share Improve this question asked Apr 20, 2015 at 19:17 FacetiousFemmeFacetiousFemme 491 silver badge4 bronze badges2 Answers
Reset to default 6Here is how you could do that with just a little bit of modification. Check out the JSFiddle.
var countdown;
function initializeTimer(){
//Initialization
countdown = $("#countdown").countdown360({
radius: 60,
seconds: 20,
label: ['sec', 'secs'],
fontColor: '#FFFFFF',
autostart: false,
onComplete: function () {
//Place AJAX call here!
//Re-start the timer once done
initializeTimer();
startTimer();
}
});
//Call this, otherwise widget does not show up on the screen. Stop immediately after.
countdown.start();
countdown.stop();
}
//Manually invoke the first initialization
initializeTimer();
function startTimer(){
countdown.start();
}
$('#countdown').click(function() {
countdown.extendTimer(2);
});
//Start the timer on the button click
$('#start').click(function(){
startTimer();
});
You would put your code to call ajax inside the onComplete
handler.
UPDATE: included code to re-start the process once plete and updated fiddle.
You nearly nailed it :)
Try that:
$('#start').click(function() {
countdown.start();
});
$('#extend').click(function() {
countdown.extendTimer(2);
});
Now you have two buttons, and both are functioning (one to start, the other to extend the timer for 2 seconds).
Here's the working code.
EDIT: @p e p's code gives more functionality like showing counter on the screen as soon as the script loads. Would go with his suggestion.
本文标签: javascriptMaking this timer start with a buttonStack Overflow
版权声明:本文标题:javascript - Making this timer start with a button - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745499969a2660983.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论