当前位置: 首页 > 图文教程 > 网络编程 > Javascript > 用CSS+JS实现的进度条效果效果

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 中的 用CSS+JS实现的进度条效果效果


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 53 ::
收藏到网摘: n/a

进度条,就是在用户进入你的网站的时候,能让用户看到网页下载了多少,这个的作用非常明显---就是让用户的等待时间变长,可以有效的弥补空间慢的缺点(当然,你空间太慢,还是建议你换下空间,呵呵)
好了,现在我先来举两个例子
一个是用FLASH实现的 (这个网上很多网站都是,不说了)
一个是用动态的GIF实现的 (这个你可以看微软官方的下载页面,也不说了)
这里,我们的重点是用 CSS+JS 实现这个效果
好了,废话不多说,我们开始
首先,写一段HTML代码
<div id="loading">
<strong id="loadcss"> 33%</strong>
</div>
好了,现在我们编写一下CSS代码
#loading {
width: 300px;
background-color: #000;
border : 2px solid #000;
}
这个是我们希望进度条的底色是 #000 ,黑色的,再加了一个边框
j
接下来多 loadcss 进行设计
#loadcss {
display : block ; /*很重要, 弄成块*/
background-color: # 0df;
text-align : center;
}
注意,这里的BLOCK 很重要的, 我们用 #0df 这种颜色来作为进度条的颜色;
好了,预览一下
h
呵呵,不过现在是整条进度条都是满的
那么,怎么弄可以显示进度呢?
这里,可以用一个巧妙的方法
把HTML代码稍微修改一下
看下面的代码:
<div id="loading">
<strong id="loadcss" style="width:33%;"> 33%</strong>
</div>
呵呵,怎么样,现在 显示的就是33% 了
但是,他是不动,对吧? 好,下面我们就用 JS 来实现 一下 (这个JS不是我设计的...)
<script language="JavaScript">
i=0;
function load () {
showload=setInterval("load()",500);
}
function setload(){
i+=5;
if (i>=100) {
clearInterval(showlaod);
}
document.getElementById("loadcss").style.width=i+"%" ;
document.getElementById("loadcss").innerHTML=i+"%";
}
</script>
OK了,这段JS主要是两个函数, 一个是 load ,用来开启进度条,
第二是 setload ,用来 控制进度条 的位置 ,在 setload设置一个计数器,每0.5秒运行一次steload.
O K了,这段JS要放在HEAD里面,然后在BODY中调用 , 即 <BODY ONLOAD="LOAD;">
呵呵,现在运行一下网页试试,呵呵,是不是成功了,呵呵.