首页
网页制作
网络编程
脚本专栏
数据库
网站运营
网络安全
平面设计
CMS教程
搜索
建站极客
网络编程
JavaScript
正文
一个已封装好的漂亮进度条
所属分类:
网络编程
/
JavaScript
阅读数: 1515
收藏 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需再刷新一下页面才能执行
]
更多精彩内容
其他人还在看
深入解析Vue 组件命名那些事
本篇文章主要介绍了深入解析Vue 组件命名那些事,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
评论 0
收藏 0
赞 0
分享
Vue学习笔记进阶篇之vue-cli安装及介绍
这篇文章主要介绍了Vue学习笔记进阶篇之vue-cli安装及介绍,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
评论 0
收藏 0
赞 0
分享
jquery版轮播图效果和extend扩展
这篇文章主要为大家详细介绍了jquery版轮播图效果,以及extend扩展的相关资料,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
评论 0
收藏 0
赞 0
分享
jQuery Validate格式验证功能实例代码(包括重名验证)
本文通过实例代码给大家介绍了jQuery Validate格式验证功能,代码中包括重名验证的方法,需要的的朋友参考下吧
评论 0
收藏 0
赞 0
分享
Angular.js中angular-ui-router的简单实践
本篇文章主要介绍了Angular.js中angular-ui-router的简单实践,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
评论 0
收藏 0
赞 0
分享
JavaScript实现二维坐标点排序效果
这篇文章主要为大家详细介绍了JavaScript实现二维坐标点排序效果,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
评论 0
收藏 0
赞 0
分享
深入理解vue2.0路由如何配置问题
本篇文章主要介绍了vue2.0路由配置问题,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
评论 0
收藏 0
赞 0
分享
基于bootstrap实现多个下拉框同时搜索功能
这篇文章主要为大家详细介绍了基于bootstrap实现多个下拉框同时搜索功能,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
评论 0
收藏 0
赞 0
分享
JavaScript 值类型和引用类型的初次研究(推荐)
这篇文章主要介绍了JavaScript 值类型和引用类型的初次研究,需要的朋友可以参考下
评论 0
收藏 0
赞 0
分享
利用jQuery异步上传文件的插件用法详解
这篇文章主要介绍了利用jQuery异步上传文件的插件用法详解,需要的朋友可以参考下
评论 0
收藏 0
赞 0
分享
查看更多
网络赚钱
更多
朋友圈疯传的万能Wi-Fi账号是假的 犯了常识性错误
网上怎么赚钱 网络赚钱需要注意哪些东西
潘定国的粉丝经济学的重点:移动互联网核心是以人为本
网站赚钱就靠广告到底行不行?
如何通过网络赚钱?互联网广告模式你知道多少
谷歌广告怎么收款?光大银行需要携带资料到柜台办理
站长故事
更多
阿里IPO在即,看阿里与京东战略和经营之比
比较适合个人站长的5种类型网站:定位 坚持 收益
我是怎么赚到人生的第一个百万的
职场中12种经典实用的管理方法和工具
精品内容永不过时,个人站长应自我审视
运营网站需要修炼三层内功 很多人都维持在第一层上