zoukankan
html css js c++ java
JS实现的进度条
//
进度条
//
<input type="button" value="start" onclick="processBar.changeMode();if(processBar.isMoving){this.value='Stop';}else{this.value='Start';}">
//
---------------------------
//
<script language="javascript" src="ProcessBar.js"></script>
//
<input type="button" value="start" onclick="(new ProcessBar()).changeMode();">
//
可实现方法:doProcessBarAction()
//
---------------------------
function
ProcessBar()
{
var
divG
=
document.createElement(
"
<div style=\
"
background: url(
'
../image/0.gif
'
) no
-
repeat;margin:
0
auto;text
-
align:center;256px;height:18px;position:absolute;top:
45
%
;left:
40
%
;font
-
size:13px;z
-
index:
1000
;\
"
></div>
"
);
var
proc
=
document.createElement(
"
<div id='proc' style=\
"
background: url(
'
../image/1.gif
'
);position:absolute;top:
0
;left:
0
;0px;height:18px;font
-
size:13px;z
-
index:
1000
;\
"
></div>
"
);
var
div2
=
document.createElement(
"
<div style='position:absolute;top:2;left:0;256px;height:18px;text-align:center;font-size:13px;background:transparent'> </div>
"
);
divG.appendChild(proc);
//
divG.appendChile(div2);
document.body.appendChild(divG);
document.execCommand(
"
BackgroundImageCache
"
,
false
,
true
);
var
obj
=
proc;
this
.isMoving
=
false
;
this
.maxLength
=
parseInt(obj.parentNode.style.width.replace(
"
px
"
,
""
));
this
.nowLength
=
parseInt(obj.style.width.replace(
"
px
"
,
""
));
this
.moveInterval
=
100
;
this
.moveRange
=
1
;
this
.timer;
this
.obj
=
obj;
ProcessBar.nowObj
=
this
;
this
.changeMode
=
function
()
{
this
.isMoving
=
!
this
.isMoving;
if
(
this
.isMoving)
{
createBgDiv();
//
创建页面蒙版
this
.timer
=
window.setInterval(ProcessBar.nowObj.moving,
this
.moveInterval);
}
else
{
window.clearInterval(
this
.timer);
}
}
this
.moving
=
function
()
{
ProcessBar.nowObj.nowLength
+=
ProcessBar.nowObj.moveRange;
ProcessBar.nowObj.obj.style.width
=
ProcessBar.nowObj.nowLength;
//
ProcessBar.nowObj.obj.parentNode.lastChild.firstChild.data = Math.ceil((ProcessBar.nowObj.nowLength/ProcessBar.nowObj.maxLength)*100) + "%";
if
(ProcessBar.nowObj.nowLength
>=
ProcessBar.nowObj.maxLength)
{
window.clearInterval(ProcessBar.nowObj.timer);
//
ProcessBar.nowObj.obj.parentNode.lastChild.firstChild.data = "Complete!";
//
执行事件
try
{
doProcessBarAction();
}
catch
(e)
{}
delBgDiv();
//
清除页面蒙版
}
}
}
//
var processBar = new ProcessBar(proc);
//
页面蒙版
function
createBgDiv()
{
var
h
=
document.body.clientHeight;
var
w
=
document.body.clientWidth;
var
div
=
document.createElement(
"
<div id='divDialogBg' style='position:absolute;visibility:visible;background:gray;filter:alpha(opacity=30);z-index:1000;left:0;top:0;
"
+
w
+
"
px;height:
"
+
h
+
"
px;'></div>
"
);
//
div.appendChild(document.createTextNode("xxxxxxxxxxxxxxxxxxxx"));
document.body.appendChild(div);
}
function
delBgDiv()
{
document.body.removeChild(document.getElementById(
"
divDialogBg
"
));
}
查看全文
相关阅读:
bootstrap以及考试复习
HTML复习
驼峰命名法和模态对话框
dom和bom
dom习题复习和讲解
DOM
属性扩展
sql防注入式攻击
自动生成编号
删除,修改,添加
原文地址:https://www.cnblogs.com/ding0910/p/1022561.html
最新文章
A Byte of Python (1)安装和运行
泛型List 扩展 比较类
JMeter 参数意义
谈谈移动端屏幕适配的几种方法
程序员MM的自白:磨人小妖精之安卓碎片化
DEF2015丨腾讯优测携专业云测试服务,亮相中国(成都)数字娱乐节
BOM
for循环终极版本练习提高 究极进化版
for循环练习+js数组
for循环练习提高
热门文章
js,For循环
js脚本语言
斯坦福大学首页制作
盒子模型和布局
Html表单和样式表
Html表单
一阶段
下拉菜单
图片轮播
JS 获取浏览器窗口大小
Copyright © 2011-2022 走看看