javascript 网页进度条简单实例

javascript 网页进度条简单实例

最近学习新的知识,遇到一个小功能网页进度条,发现一篇文章还是不错的,这里记录下,也许能帮助到大家,

实例代码:

<!DOCTYPE html> <html> <head> <style> #box {float:left;width:100%;height:18px;border:1px solid;} #bar {float:left;width:100%;height:18px;border:0px;background:#00f;} </style> </head> <body> <div> <div></div> </div> <script language="javascript"> var total = 6480; //总数 var curN = 4480; //当前值 function show() { var box = document.getElementById("box"); var o = document.getElementById("bar"); o.style.width = ((curN / total) * 200) + 'px'; //200是外框的宽度 } show(); </script> </body> </html>

取反:

<!DOCTYPE html> <html> <head> <style> #box {float:left;width:200px;height:18px;border:1px solid;} #bar {float:left;width:100%;height:18px;border:0px;background:#00f;} </style> </head> <body> <div> <div></div> </div> <script language="javascript"> var total = 6480; //总数 var curN = 6400; //当前值 var baseNub = total - curN; function show() { var box = document.getElementById("box"); var o = document.getElementById("bar"); o.style.width = ((baseNub / total) * 200) + 'px'; //200是外框的宽度 } show(); </script> </body> </html>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wwzfpp.html