如何修改以下显示栏上的 hh:mm:ss 的示例?
看看这个Codepen代码。
function progress(timeleft, timetotal, $element) {
var progressBarWidth = timeleft * $element.width() / timetotal;
$element.find('div').animate({ width: progressBarWidth }, 500).html(Math.floor(timeleft/60) + ":"+ timeleft%60);
if(timeleft > 0) {
setTimeout(function() {
progress(timeleft - 1, timetotal, $element);
}, 1000);
}
};
progress(600, 600, $('#progressBar'));
提前致谢。
最佳答案
使用以下代码更新您的 JS
。
function progress(timeleft, timetotal, $element) {
var progressBarWidth = timeleft * $element.width() / timetotal;
//newcode
var hrs ;
var mins = Math.floor(timeleft/60);
var secs = timeleft%60;
if(mins.toString().length < 2){
mins = "0" + mins;
};
if(secs.toString().length < 2){
secs = "0" + secs;
};
if(!hrs){
hrs = "00"
};
$element.find('div').animate({ width: progressBarWidth }, 500).html(hrs +":"+ mins+ " :" + secs);
if(timeleft > 0) {
setTimeout(function() {
progress(timeleft - 1, timetotal, $element);
}, 1000);
}
};
progress(600, 600, $('#progressBar'));
您可以查看此 Code pen link 中的代码
关于javascript - 显示 hh :mm:ss on this code?(进度条),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57883953/