0

可能重复:
Jquery::Ajax 驱动的进度条?

我需要创建某种倒计时

请求在 Html

count = Math.floor((futureDate-today)/1000);

if(count > 0) //move Loading bar by percent  

我怎样才能拥有与电池动画相同的代码加载栏?

就像这个演示一样 ,这是我用来递减计数器的演示代码:

4

1 回答 1

1

您还需要一个开始日期才能获得电池百分比。检查这个小提琴:http: //jsfiddle.net/uhGjz/

<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>MyBattery</title>
  <style type='text/css'>
#bat {
    width:100px;
    height: 30px;
    border: 1px solid;
    position: relative;
}
#fill {
    height: 100%;
    background-color: red;
    width: 0%;
}
  </style>
  <script type='text/javascript' src='http://code.jquery.com/jquery-1.7.1.js'></script>
  <script type='text/javascript'>
$(function(){
var now = new Date();
var today = now.getTime();
var pastDate = Date.parse("Tue, 1 Jan 2012 00:00:00 GMT");
var futureDate = Date.parse("Tue, 1 Aug 2012 00:00:00 GMT");
var count = Math.floor((today-pastDate)/(futureDate-pastDate)*100);

if(count > 0) { //move Loading bar by percent 
    $('#fill').animate({
       width: count+"%"
    }, 1000);
}

}); 
</script>
</head>
<body>
  <div id="bat"><div id="fill"></div></div>
  <!-- Your own content! -->
</body>
</html>
于 2012-05-22T15:29:20.710 回答