我正在创建一个包含里程碑的UI,我将使用进度条来显示这个.
我试图提出从里程碑设置完成日期到今天日期的百分比.
例如,如果我有一个名为"Live to Site"的里程碑,将于2015年12月1日发生,我将里程碑放在1月1日,我想确定从开始日期到结束日期的百分比.
小提琴:http://jsfiddle.net/zz4c16fx/2/
var start = new Date(2015,0,1), // Jan 1, 2015 - The date we put this milestone in
end = new Date(2015,7,24), // June 24, 2015 - The date the milestone is due
today = new Date(), // April 23, 2015
p = Math.round(100-((end - start) * 100 ) / today) + '%';
// Update the progress bar
$('.bar').css( "width", p ).after().append(p);
Run Code Online (Sandbox Code Playgroud)
这是我的尝试,但要么我的数学错了,要么我正在考虑这个错误.它返回的数字是99%.我觉得这个数字应该会低一些,看看我们今天还有1.5个月的时间.
我的最终结果是显示一个进度条,显示我们与开始日期,结束日期和今天日期的完成日期有多接近.
试试这个:
var start = new Date(2015, 0, 1), // Jan 1, 2015
end = new Date(2015, 7, 24), // August 24, 2015
today = new Date(), // April 23, 2015
p = Math.round(((today - start) / (end - start)) * 100) + '%';
// Update the progress bar
$('.bar').css("width", p).after().append(p);
Run Code Online (Sandbox Code Playgroud)
演示:http://jsfiddle.net/zz4c16fx/6/
| 归档时间: |
|
| 查看次数: |
4072 次 |
| 最近记录: |