jquery css进度条效果代码

发布时间:2019-08-26编辑:脚本学堂
分享一例jquery与css样式实现的进度条代码,jquery进度条代码的简单例子,相比纯js实现的进度条,在实现代码上要简单的多。

jquery/jindutiao/ target=_blank class=infotextkey>jquery进度条代码:

复制代码 代码示例:

<!doctype html public "-//w3c//dtd xhtml 1.0 strict//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>javascript progress bar 进度条代码 - www.jb200.com</title>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<style type="text/css">
#progress {background: white; height: 20px; padding: 2px; border: 1px solid green; margin: 2px;}
#progress span {background: green; height: 16px; text-align: center; padding: 1px; margin: 1px;
display: block; color: yellow; font-weight: bold; font-size: 14px; width: 0%;}
</style>

<script type="text/javascript">
var progress_node_id = "progress";
function SetProgress(progress) {
if (progress) {
$("#" + progress_node_id + " > span").css("width", String(progress) + "%");
$("#" + progress_node_id + " > span").html(String(progress) + "%");
}
}

var i = 0;
function doProgress() {
if (i > 100) {
alert("Progress Bar Finished!");
return;
}

if (i <= 100) {
setTimeout("doProgress()", 500);
SetProgress(i);
i++;
}
}

$(document).ready(function() {
doProgress();
});
</script>
</head>
<body>
<h1>Javascript 进度条 Demo</h1>
<p>以上jquery进度条代码的原理:使用 Javascript 控制 SPAN CSS 的宽度(以及其他的样式)</p>
<div id="progress"><span></span></div>
</body>
</html>