zoukankan      html  css  js  c++  java
  • Javascript jquery css 写的简单进度条控件

    很多的时候用户需要等待你“臃肿”的 Javascript 代码处理完成(Web 2.0 的特色)。期间或许加入一个类似于进度条的东西让用户有点“安慰”。这个东西实现起来并不复杂,无非就是获得总的处理条目,然后获得一个百分比,再显示输出。

    通过我们伟大的 CSS,可以实现非常漂亮的进度条样式。加上 Javascript 的效果,就可以完全“欺骗”我们的用户,让他们有耐心等待浏览器处理完成。上述的原理已经知道了,那么就可以直接看代码了。本人使用的还是 jQuery 框架,因为这样简短的代码可能会更容易理解。 
    当然这个控件还有很多需要完成的地方,我仅仅是提供了一种遵循 Web 标准的实现思路。废话不多说.
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"> 
        <head> 
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
            <title>Javascript Progress Bar Demo - jb51.net</title> 
            <script type="text/javascript" src="http://www.jb51.net/jslib/jquery/jquery.js"></script> 
            <style type="text/css"> 
                #progress {background: white; height: 20px; padding: 2px; border: 1px solid green; margin: 2px;} 
                #progress span {background: green; height: 16px; text-align: center; padding: 1px; margin: 1px; 
                    display: block; color: yellow; font-weight: bold; font-size: 14px; 0%;} 
            </style> 
     
            <script type="text/javascript"> 
     
                var progress_node_id = "progress"; 
                function SetProgress(progress) { 
                    if (progress) { 
                        $("#" + progress_node_id + " > span").css("width", String(progress) + "%"); 
                        $("#" + progress_node_id + " > span").html(String(progress) + "%"); 
                    } 
                } 
     
                var i = 0; 
                function doProgress() { 
                    if (i > 100) { 
                        alert("Progress Bar Finished!"); 
                        return; 
                    } 
     
                    if (i <= 100) { 
                        setTimeout("doProgress()", 500); 
                        SetProgress(i); 
                        i++; 
                    } 
                } 
     
                $(document).ready(function() { 
                    doProgress(); 
                }); 
            </script> 
    </head> 
     
    <body> 
        <h1>Javascript 进度条 Demo</h1> 
        <p>原理就是使用 Javascript 控制 SPAN CSS 的宽度(以及其他的样式),详细信息可以参见链接:<a  
    href="http://www.huiyi8.com/sc/24054.html">http://www.huiyi8.com/sc/24054.html</a></p> 
        <div id="progress"><span> </span></div> 
    </body> 
    </html> 
     
     
    源于:http://www.huiyi8.com/jiaoben/
  • 相关阅读:
    C#(99):串口编程 System.IO.Ports.SerialPort类
    FastReport.Net的使用
    MongoDB(07):查询文档
    MongoDB(06):文档操作
    HIVE metastore Duplicate key name 'PCS_STATS_IDX' (state=42000,code=1061)
    RSync实现文件备份同步
    env: /etc/init.d/redis: Permission denied
    Multiple MySQL running but PID file could not be found
    centos 6.5卸载Mysql
    web应用性能测试-Tomcat 7 连接数和线程数配置
  • 原文地址:https://www.cnblogs.com/lhrs/p/4094557.html
Copyright © 2011-2022 走看看