2013-02-11 87 views
-1

我有一个函数,它根据它在div .days-due中找到的数字来设置引导程序进度条。它工作正常,但进度条与我想要的宽度相反。找到反向百分比

如何反转progBarValue号码?

function daysUntil(year, month, day) { 
    var now = new Date(), 
     dateEnd = new Date(year, month - 1, day), // months are zero-based 
     days = (dateEnd - now)/1000/60/60/24; // convert milliseconds to days 

    return Math.round(days); 
} 

// find percentage to due date 
$('#paging1 ul li').each(function() { 

    var monthDue = $(this).find('.month').text(); 
    var dayDue = $(this).find('.day').text(); 
    var yearDue = $(this).find('.year').text(); 

    $(this).find('.days-due').text(daysUntil(yearDue, monthDue, dayDue)); 

    // progress bar 
    // find number of days until due date 
    var progBarValue = $(this).find('.days-due').text(); 
    // limit days due to no more than 100% 
    progBarValue = progBarValue > 100 ? 100 : progBarValue; 
    // set progress bar width 
    $(this).find('.bar').width(progBarValue +"%"); 

}); 
+2

从100减去你当前的百分比。IE,如果你完成了10%,你没有完成90%。这就是*百分比*的含义。这是一个数学问题,而不是编程问题。 – meagar 2013-02-11 17:46:35

回答

3

恩,$(this).find('.bar').width((100 - progBarValue) +"%");