JGUI源码:实现简单进度条(19)

程序效果如下

实现进度条动画主要有两种方法:(1)使用缓动,(2)使用Jquery Animate,本文使用第二种方法,先实现代码,后续进行控件封装

<style>
      .jgui-processbar .loading
      {
        background-color: #22B581;
        height: 100%;
        width:0%;
        color:white;
        text-align: center;
      }
    </style>
  </head>
  <body>
    <div>这是进度条演示代码</div>
    <script type="text/javascript">
      $(function() {
        showProcess1();
        showProcess2();
      });
      function showProcess1()
      {
        $('#processbar1 .loading').animate({'width':'100%'},500);
      }
      function showProcess2()
      {
        $('#processbar2 .loading').animate(
          {
            'width':'100%'},
            {
              step:function(now,fx){
                if(fx.prop=="width"){
                  var pos=Math.round(fx.pos*100);
                  $('#processbar2 .loading').html(pos+'%');
                }
            },
            duration:1000});
      }
    </script>
    <div class="jgui-processbar" id="processbar1"  style="position:relative;width:320px;height:20px;border: #12A571 1px solid">
     <div class="loading"></div>
    </div>
    <div style="margin:10px">
    </div>
    <div class="jgui-processbar" id="processbar2"  style="position:relative;width:320px;height:20px;border: #12A571 1px solid">
      <div class="loading"></div>
     </div>

需要注意的是,div  loading需要设置高度100%,因为div 默认的高度是auto,如果没有内容的话高度为0.
第一种方法单纯显示动画,第二种方法会更新进度到界面上。

写好后,发现loading宽度比父div宽度要宽,加上relative属性即可解决

 <style>
      .jgui-processbar
      {
        position: relative;
      }
      .jgui-processbar .loading
      {
        background-color: #22B581;
        height: 100%;
        width:0%;
        color:white;
        text-align: center;
        position: relative;
      }
    </style>

 

界面演示:www.jgui.com

 

转载于:https://www.cnblogs.com/zhaogaojian/p/10562374.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值