jQuery进度条的使用方法

下载jqueryprogressbar.js

源码如下:

(function($) {   
    //Main Method
    $.fn.reportprogress = function(val,maxVal) {           
        var max=100;
        if(maxVal)
            max=maxVal;
        return this.each(
            function(){       
                var div=$(this);
                var innerdiv=div.find(".progress");
               
                if(innerdiv.length!=1){                       
                    innerdiv=$("<div class='progress'></div>");                   
                    div.append("<div class='text'>&nbsp;</div>");
                    $("<span class='text'>&nbsp;</span>").css("width",div.width()).appendTo(innerdiv);                   
                    div.append(innerdiv);                   
                }
                var width=Math.round(val/max*100);
                innerdiv.css("width",width+"%");   
                div.find(".text").html(width+" %");
            }
        );
    };
})(jQuery);

 

页面代码:

<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
 <script src="jquery.js" type="text/javascript"></script>
<SCRIPT src="jqueryprogressbar.js" type="text/javascript"></SCRIPT>

<SCRIPT type=text/javascript>
    var pct=0;
    var handle=0;
    function update(){
            $("#progressbar").reportprogress(++pct);
            if(pct==100){                                                //设定总长度值
                clearInterval(handle);
                $("#run").val("start");
                pct=0;
            }
    }
    jQuery(function($){
        $("#run").click(
            function(){
                if(this.value=="start"){
                    handle=setInterval("update()",100);               //设定增长的时间
                    this.value="stop";
                }else{
                    clearInterval(handle);
                    this.value="start";
                }
            }
        );
        $("#reset").click(function(){
            pct=0;
            $("#progressbar").reportprogress(0);
        });
    });
</SCRIPT>

<STYLE>
    #progressbar {
        BORDER-RIGHT: black 1px solid;
        BORDER-TOP: black 1px solid;
        BORDER-LEFT: black 1px solid;
        WIDTH: 200px;
        COLOR: black;
        BORDER-BOTTOM: black 1px solid;
        POSITION: relative; HEIGHT: 20px
    }
    #progressbar DIV.progress {
        OVERFLOW: hidden;
        WIDTH: 0px;
        POSITION: absolute;
        HEIGHT: 100%;
        BACKGROUND-COLOR: blue;
    }
    #progressbar DIV.progress .text {
        COLOR: white;
        POSITION: absolute;
        TEXT-ALIGN: center; FONT-SIZE:larger;
    }
    #progressbar DIV.text {
        WIDTH: 100%;
        POSITION: absolute;
        HEIGHT: 100%;
        TEXT-ALIGN: center;
        FONT-SIZE:larger;
    }
</STYLE>
</HEAD>
    <BODY>
    <DIV id="progressbar">
       
    </DIV>
    <INPUT id="run" type="button" value="start"> <INPUT id="reset" type="button" value="reset">
    </DIV>
    </DIV>
    </DIV>
    </BODY>
</HTML>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值