//onclick event for progressbar
document.getElementById("start_progressbar").onclick = progress;
//progress bar
function progress(timeleft, timetotal, $element) {
var progressBarWidth = (timetotal - timeleft) * ($element.width() / timetotal);
$element.find('div').animate({
width: progressBarWidth
}, timeleft == timetotal ? 0 : 1000, "linear"); //.html(timeleft + " seconds to go"); //comment out -html if no text should appear in the progress bar
if (timeleft > 0) {
setTimeout(function() {
progress(timeleft - 1, timetotal, $element);
}, 1000);
}
}
progress(5, 5, $('#progress_bar')); // put the desired number of secons here
//onclick event for progressbar
document.getElementById("start_timer").onclick = startTimer;
//countdown timer
function startTimer(duration, display) {
var timer = duration,
minutes, seconds;
setInterval(function() {
minutes = parseInt(timer / 60, 10);
seconds = parseInt(timer % 60, 10);
minutes = minutes < 10 ? "0" + minutes : minutes;
seconds = seconds < 10 ? "0" + seconds : seconds;
display.text(minutes + ":" + seconds);
if (--timer < 0) {
timer = 0; //set to "0" if you want timer to stop, or to same value as time to cycle continously
}
}, 1000);
}
jQuery(function($) {
var fiveMinutes = 5 * 1, //put the desired time for the countdown here (format seconds (max60)x multiplier)
display = $('#countdown_timer');
startTimer(fiveMinutes, display);
});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.