j使用时区/开始日期/结束日期查询进度条
jQuery progress bar with timezone/start date/end date
我使用的是:
var start = new Date();
var maxTime = 835000;
var timeoutVal = Math.floor(maxTime/100);
animateUpdate();
function updateProgress(percentage) {
$('#pbar_innerdiv').css("width", percentage + "%");
$('#pbar_innertext').text(percentage + "%");
}
function animateUpdate() {
var now = new Date();
var timeDiff = now.getTime() - start.getTime();
var perc = Math.round((timeDiff/maxTime)*100);
if (perc <= 100) {
updateProgress(perc);
setTimeout(animateUpdate, timeoutVal);
}
}
https://jsfiddle.net/6h74c/3/
它是有效的。但它只有在加载页面并开始计算maxTime
(以毫秒为单位(时才有效。这没用。我需要设置开始日期和结束日期,例如3天5小时(包括时区,输入日期时还需要包括小时(。因此,如果用户在2天内访问,他将已经看到进度条~70%完成,以此类推
这是在建工地的进度条。因此,我们可以让访问者知道网站完成需要多长时间。
给你。让我们在UTC时区开始。
// year,month,day,hours,minutes,seconds,millisec
// set to recent UTC time in past.
var start = new Date(Date.UTC(2015, 6, 4, 7, 23, 0, 0));
var maxTime = 835000;
var timeoutVal = Math.floor(maxTime / 100);
animateUpdate();
function updateProgress(percentage) {
$('#pbar_innerdiv').css("width", percentage + "%");
$('#pbar_innertext').text(percentage + "%");
}
function animateUpdate() {
var now = new Date();
var timeDiff = now.getTime() - start.getTime();
var perc = Math.round((timeDiff / maxTime) * 100);
console.log(perc);
if (perc <= 100) {
updateProgress(perc);
setTimeout(animateUpdate, timeoutVal);
} else { // It got 100%
updateProgress(100);
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="pbar_outerdiv" style="width: 300px; height: 20px; border: 1px solid grey; z-index: 1; position: relative; border-radius: 5px; -moz-border-radius: 5px;">
<div id="pbar_innerdiv" style="background-color: lightblue; z-index: 2; height: 100%; width: 0%;"></div>
<div id="pbar_innertext" style="z-index: 3; position: absolute; top: 0; left: 0; width: 100%; height: 100%; color: black; font-weight: bold; text-align: center;">0%</div>
</div>
希望得到帮助。
相关文章:
- Solr查询以按日期月份获取数据&年
- Mongoose查询嵌套文档的时间或多或少为某个日期
- Mongoose查询在两个日期时间之间提取数据
- 如何使用 OData 查询选项按日期进行筛选
- XML查询日期范围查找
- 查询日期时间选择器未在另一个函数调用中获取日期
- 使用所有登录时间按日期对查询进行休眠分组
- Parse.com:查询日期和UTC
- mongoDB动态查询中的日期筛选器
- j查询验证单独的年、月、日的日期字段
- 从MS SQL查询到谷歌图表(Razor)的日期值
- j查询保存时间和到期日期
- parse.com - 我如何仅使用 javascript 创建等于 createdAt 日期的查询
- j查询日期选取器不显示时间输入值
- 按日期范围查询 Firebase
- Meteor:如何使用Momentjs在Mongodb中添加和查询日期
- 以可在 Azure 移动服务 (Javascript) 中查询的方式保存日期时间
- 我可以按日期查询MongoDB ObjectId吗?
- 将_id用于日期查询条件
- j使用时区/开始日期/结束日期查询进度条