首页
网页制作
网络编程
脚本专栏
数据库
网站运营
网络安全
平面设计
CMS教程
搜索
建站极客
网络编程
JavaScript
正文
一个已封装好的漂亮进度条
所属分类:
网络编程
/
JavaScript
阅读数: 1539
收藏 0
赞 0
分享
复制代码
代码如下:
<body>
<input type="button" value="start" onclick="processBar.changeMode();if(processBar.isMoving){this.value='Stop';}else{this.value='Start';}">
</body>
<script>
document.execCommand("BackgroundImageCache",false,true);
function ProcessBar(){
this.width = 256;
this.height = 18;
this.top = 0;
this.left = 0;
this.backImg = "process_back.gif";
this.foreImg = "process.gif";
this.backDiv = document.createElement("div");
this.foreDiv = document.createElement("div");
this.fontDiv = document.createElement("div");
this.isMoving = false;
this.nowLength = 0;
this.moveInterval = 100;
this.moveRange = 1;
this.timer;
ProcessBar.nowObj = this;
this.init = function(){
this.foreDiv.style.backgroundImage = "url(" + this.foreImg + ")";
this.foreDiv.style.backgroundRepeat = "no-repeat";
this.foreDiv.style.position = "absolute";
this.foreDiv.style.width = this.nowLength;
this.foreDiv.style.height = this.height;
this.foreDiv.style.top = 0;
this.foreDiv.style.left = 0;
this.fontDiv.style.background = "transparent";
this.fontDiv.style.position = "absolute";
this.fontDiv.style.width = this.width;
this.fontDiv.style.height = this.height;
this.fontDiv.style.top = 2;
this.fontDiv.style.left = 0;
this.fontDiv.style.textAlign = "center";
this.fontDiv.style.fontSize = "13px";
this.fontDiv.appendChild(document.createTextNode(" "));
this.backDiv.style.backgroundImage = "url(" + this.backImg + ")";
this.backDiv.style.backgroundRepeat = "no-repeat";
this.backDiv.style.position = "absolute";
this.backDiv.style.width = this.width;
this.backDiv.style.height = this.height;
this.backDiv.style.top = this.top;
this.backDiv.style.left = this.left;
this.backDiv.appendChild(this.foreDiv);
this.backDiv.appendChild(this.fontDiv);
document.body.appendChild(this.backDiv);
}
this.changeMode = function(){
this.isMoving = !this.isMoving;
if(this.isMoving){
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.foreDiv.style.width = ProcessBar.nowObj.nowLength;
ProcessBar.nowObj.fontDiv.firstChild.data = Math.ceil((ProcessBar.nowObj.nowLength/ProcessBar.nowObj.width )*100) + "%";
if(ProcessBar.nowObj.nowLength >= ProcessBar.nowObj.width ){
window.clearInterval(ProcessBar.nowObj.timer);
ProcessBar.nowObj.fontDiv.firstChild.data = "Complete!";
}
}
}
var processBar = new ProcessBar();
processBar.backImg = "https://zhanzhang360.qulang.net/imgupload/001055/2007415102314868.gif"; processBar.foreImg = "https://zhanzhang360.qulang.net/imgupload/001055/2007415102319734.gif"; processBar.top = 100;
processBar.left = 20;
processBar.init();
</script>
[Ctrl+A 全选 注:
引入外部Js需再刷新一下页面才能执行
]
更多精彩内容
其他人还在看
JSONP原理及简单实现
这篇文章主要介绍了JSONP原理及简单实现的相关资料,非常不错具有参考借鉴价值,需要的朋友可以参考下
评论 0
收藏 0
赞 0
分享
浅析JSONP技术原理及实现
这篇文章主要介绍了浅析JSONP技术原理及实现 的相关资料,非常不错具有参考借鉴价值,需要的朋友可以参考下
评论 0
收藏 0
赞 0
分享
使用Web Uploader实现多文件上传
这篇文章主要介绍了使用Web Uploader实现多文件上传的相关资料,非常不错具有参考借鉴价值,需要的朋友可以参考下
评论 0
收藏 0
赞 0
分享
json的使用小结
下面小编就为大家带来一篇json的使用小结。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
评论 0
收藏 0
赞 0
分享
非常实用的js验证框架实现源码 附原理方法
这篇文章主要为大家详细介绍了一个非常实用的js验证框架实现源码,并附原理方法,感兴趣的小伙伴们可以参考一下
评论 0
收藏 0
赞 0
分享
js验证框架之RealyEasy验证详解
这篇文章主要为大家详细介绍了js验证框架之RealyEasy验证,记录了RealyEasy验证的使用步骤,感兴趣的小伙伴们可以参考一下
评论 0
收藏 0
赞 0
分享
webpack中引用jquery的简单实现
下面小编就为大家带来一篇webpack中引用jquery的简单实现。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
评论 0
收藏 0
赞 0
分享
JavaScript必知必会(五) eval 的使用
这篇文章主要介绍了JavaScript必知必会(五) eval 的使用 的相关资料,非常不错具有参考借鉴价值,需要的朋友可以参考下
评论 0
收藏 0
赞 0
分享
JavaScript必知必会(六) delete in instanceof
这篇文章主要介绍了JavaScript必知必会(六) delete in instanceof的相关资料,非常不错具有参考借鉴价值,需要的朋友可以参考下
评论 0
收藏 0
赞 0
分享
JavaScript必知必会(七)js对象继承
这篇文章主要介绍了JavaScript必知必会(七)js对象继承的相关资料,非常不错具有参考借鉴价值,需要的朋友可以参考下
评论 0
收藏 0
赞 0
分享
查看更多
网络赚钱
更多
网赚之谈:如何用最少的钱做最大化的网站推广
网络公司的普通程序员如何利用QQ营销月赚万元
怎么进入微店买东西?微店购物流程图文介绍
全面剖析日赚500元项目的骗局
Google
Papi酱首次直播的八大平台是哪些 打赏90万服不服
站长故事
更多
喜马拉雅创始人自述:网络电台一年半获取7000万用户
被低估的公司(一):写在阿里IPO之后
论诺基亚之死!
曾与前苹果CEO搭档 Zeta公司营收过亿美元背后的经验与教训
站长做好以下三个步骤 长期盈利不是难事
运营网站需要修炼三层内功 很多人都维持在第一层上