Progress,进度条,用于上传、下载等耗时并且需要显示进度的场景,用户可以随时中断该操作。

    完整的进度条结构如下:

    1. <div class="weui-progress">
    2. <div class="weui-progress__bar">
    3. <div class="weui-progress__inner-bar js_progress" style="width: 0%;"></div>
    4. </div>
    5. <a href="javascript:;" class="weui-progress__opr">
    6. <i class="weui-icon-cancel"></i>
    7. </a>
    8. </div>
    9. <br>
    10. <div class="weui-progress">
    11. <div class="weui-progress__bar">
    12. <div class="weui-progress__inner-bar js_progress" style="width: 50%;"></div>
    13. </div>
    14. <a href="javascript:;" class="weui-progress__opr">
    15. <i class="weui-icon-cancel"></i>
    16. </a>
    17. </div>
    18. <br>
    19. <div class="weui-progress">
    20. <div class="weui-progress__bar">
    21. <div class="weui-progress__inner-bar js_progress" style="width: 80%;"></div>
    22. </div>
    23. <a href="javascript:;" class="weui-progress__opr">
    24. <i class="weui-icon-cancel"></i>
    25. </a>
    26. </div>
    27. <div class="weui-btn-area">
    28. <a href="javascript:;" class="weui-btn weui-btn_primary" id="btnStartProgress">上传</a>
    29. </div>

    div.weui-progress__inner-bar 的默认宽度为 0, 改变改元素的宽度(百分比),即可显示不同的进度。

    点击 a.weui-progress__opr 元素,可以中断/取消正在进行的操作;如果不需要该操作,则可以省略掉该结构,进度条长度自动适应。

    下面模拟改变进度条的值:

    1. $(function(){
    2. var progress = 0;
    3. var $progress = $('.weui-progress__inner-bar');
    4.  
    5. function uploading(){
    6. $progress.width(++progress % 100 + '%');
    7. setTimeout(uploading, 20);
    8. }
    9.  
    10. setTimeout(uploading, 20);
    11. });

    预览效果如下:

    image

    原文: https://github.com/Tencent/weui/wiki/Progress