我需要创建某种倒计时
请求Html
count = Math.floor((futureDate-today)/1000);
if(count > 0) //move Loading bar by percent
如何使用具有电池动画的代码的相同加载栏?
Like this demo 这是我demo cod e,我以前用来递减计数器:
答案 0 :(得分: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>