最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

js實現自定義進度條效果

 更新時間:2017年03月15日 09:04:40   作者:lqm123  
本文主要介紹了js實現自定義進度條效果的實例。具有很好的參考價值。下面跟著小編一起來看下吧

效果圖:

代碼如下:

<!DOCTYPE html>
<html>
 <head>
  <meta charset="utf-8">
  <title>Staged progress bar</title>
  <style type="text/css">
   *{margin:0;padding:0;}
   html,body{height:100%;}
   ul{list-style:none;}
   .cf:after{content:"";display:block;clear:both;height: 0;}
   #bar{height:20px;margin:100px 10px; margin-left: 50px}
   #bar div{float:left;position:relative;}
   #bar .staged, #bar .progress{border-color:#4CA8FF;}
   #bar .staged i{position:relative;overflow:hidden;display:block;width:inherit;height:inherit;}
   #bar .staged i:before{content:"";display:block;width:0;height:inherit;border-radius:50%;}
   #bar .progress {width:120px;height:inherit;margin-left:-4px;z-index:1;border-style:solid;border-width:2px 0;}
   #bar .progress:nth-child(2) i{border-left-width:2px;border-top-left-radius:6px;border-bottom-left-radius:6px;}
   #bar .progress:nth-child(2){border-left-width:2px;border-top-left-radius:10px;border-bottom-left-radius:10px;}
   #bar .progress:last-child{border-right-width:2px;border-top-right-radius:10px;border-bottom-right-radius:10px;}
   #bar .progress i{width:0;height:inherit;display:block;border-radius:0 10px 10px 0;position:relative;font-style:normal;}
   #bar .progress, #bar .staged{background:#7d7d7d;}
   #bar .sp i:before, #bar .progress i{background:#4CA8FF;}
   #bar .staged:not(:first-child){margin-left:-4px; }
   #bar .staged:before{position:absolute;content:attr(data-text);width:inherit;height:inherit;top:90%;left:0;}
   #bar .staged:after{content:attr(data-value);color:#fff;width:inherit;height:inherit;position:absolute;top:0;left:0;}
   #bar .sp i:before{width:100%;transition:width 1s;}
   .msg:before, .msg:after{display:block;position:absolute;border-style:solid;border-color:#ccc;background:#fff;top:30px;}
   .msg:before{content:attr(data-text);width:200px;height:40px;line-height:40px;font-size:12px;text-align:center;border-radius:4px;border-width:1px;top:-68px;left:calc(100% - 114px);}
   .msg:after{content:"";width:14px;height:14px;transform:rotate(45deg);border-width:0 1px 1px 0;top:-34px;left:calc(100% - 20px);}
  </style>
 </head>
 <body>
  <div id="bar" class="cf" data-value="8000" data-text="還有 [number] 點進度加載完成">
   <div class="staged sp" data-value="0" ><i></i></div>
   <div class="progress"><i></i></div>
   <div class="staged" data-value="200" "><i></i></div>
   <div class="progress"><i></i></div>
   <div class="staged" data-value="1000" ><i></i></div>
   <div class="progress"><i></i></div>
   <div class="staged" data-value="5000" ><i></i></div>
   <div class="progress"><i></i></div>
   <div class="staged" data-value="10000" ><i></i></div>
   <div class="progress"><i></i></div>
  </div>
  <script type="text/javascript">
   var progressBar = (function(){
    var $ = function(sele){
     return document.querySelectorAll(sele);
    }
    return function(a){
     var getValue = function(obj,attr){
      return Number(obj.getAttribute(a.value));
     }
     var box = $(a.box)[0];
     var value = getValue(box);
     var text = box.getAttribute(a.text);
     var staged = $(a.staged);
     var progress = $(a.progress);
     var i = 0, index = 0, num = 0, numV = 0, n = 1, af_index = 0, timeout = 0, stopAm = null;
     var af = function(fn){
      if(!requestAnimationFrame || !cancelAnimationFrame){
       clearTimeout(af_index);
       af_index = setTimeout(fn, 1000/60);
      }
      else{
       cancelAnimationFrame(af_index);
       af_index = requestAnimationFrame(fn);
      }
     }
     var setMsg = function(){
      var msg = progress[index];
      if(a.note){
        var arr = text.split(a.note);
        text = arr[0] + n + arr[1];
      }
      msg.setAttribute("data-text", text);
      msg.className = a.msg;
     }
     var animation = function(){
      if(i == 0){
       if(staged.length == index + 1){
        numV = value * 2;
       }
       else numV = getValue(staged[index + 1]);
       if(n == 0) {
        progress[index].style.width = "1%";
        return
       };
       if(n < 0 && staged.length > index + 1){
        n = numV - value;
        if(Number(progress[index].style.width.split("%")[0])<5) progress[index].style.width = "3%";
        setMsg();
        return;
       }
      }
      num = Math.ceil(++i * numV / 100);
      if(num > value){
       num = value;
       //console.log(num)
       n = numV - num;
       if(n > 0){
        if(staged.length > index + 1) setMsg();
        return;
       }
      }
      if(i == 100){
       staged[index + 1].className += " " + a.stagedProgress;
      }
      if(i > 105){ //105% 寬,自己根據樣式調整。
       num = numV;
       index++;
       i = 0;
       timeout = setTimeout(function(){
        af(animation);
        clearTimeout(timeout);
       }, a.stagedSleep);
       return;
      }
      progress[index].style.width = i + "%";
      af(animation);
     }
     animation()
    }
   })();
   progressBar({
    box : "#bar",
    text : "data-text", // box 的屬性
    note : "[number]", // box 的屬性 (可以省略,計算好直接寫入提示語句。);
    msg : "msg",
    staged : ".staged",
    progress : ".progress i",
    stagedProgress : "sp",
    value : "data-value",
    stagedSleep : "900",
    sleep : "3000"
   });
  </script>
 </body>
</html>

以上就是本文的全部內容,希望本文的內容對大家的學習或者工作能帶來一定的幫助,同時也希望多多支持腳本之家!

相關文章

  • JavaScript實現的MD5算法完整實例

    JavaScript實現的MD5算法完整實例

    這篇文章主要介紹了JavaScript實現的MD5算法,以完整實例形式分析了基于JavaScript實現MD5算法的具體步驟與相關技巧,需要的朋友可以參考下
    2016-02-02
  • JavaScript中Blob的具體實現

    JavaScript中Blob的具體實現

    Blob常用于處理文件數據、圖像數據、音頻數據,本文主要介紹了JavaScript中URL和Blob的具體實現,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2024-08-08
  • JavaScript實現簡單生成隨機顏色的方法

    JavaScript實現簡單生成隨機顏色的方法

    這篇文章主要介紹了JavaScript實現簡單生成隨機顏色的方法,涉及javascript隨機數與字符串運算及頁面元素屬性動態(tài)操作相關實現技巧,需要的朋友可以參考下
    2017-09-09
  • 使用mock.js隨機數據和使用express輸出json接口的實現方法

    使用mock.js隨機數據和使用express輸出json接口的實現方法

    這篇文章主要介紹了使用mock.js隨機數據和使用express輸出json接口的實現方法,需要的朋友可以參考下
    2018-01-01
  • javascript 組合按鍵事件監(jiān)聽實現代碼

    javascript 組合按鍵事件監(jiān)聽實現代碼

    這篇文章主要介紹了javascript 組合按鍵事件監(jiān)聽實現代碼的相關資料,需要的朋友可以參考下
    2017-02-02
  • 使用TypeScript接口優(yōu)化數據結構的示例詳解

    使用TypeScript接口優(yōu)化數據結構的示例詳解

    在現代軟件開發(fā)中,數據結構的設計至關重要,它直接影響到程序的性能和可維護性,TypeScript 作為一種靜態(tài)類型的超集,為 JavaScript 帶來了類型系統(tǒng),本文將探討如何利用 TypeScript 的接口(Interfaces)來優(yōu)化數據結構,需要的朋友可以參考下
    2024-09-09
  • javascript用defineProperty實現簡單的雙向綁定方法

    javascript用defineProperty實現簡單的雙向綁定方法

    這篇文章主要介紹了javascript用defineProperty實現簡單的雙向綁定方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-04-04
  • js簡單實現表單中點擊按鈕動態(tài)增加輸入框數量的方法

    js簡單實現表單中點擊按鈕動態(tài)增加輸入框數量的方法

    這篇文章主要介紹了js簡單實現表單中點擊按鈕動態(tài)增加輸入框數量的方法,涉及javascript鼠標點擊事件及insertAdjacentHTML方法的相關使用技巧,需要的朋友可以參考下
    2015-08-08
  • Bootstarp風格的toggle效果分享

    Bootstarp風格的toggle效果分享

    這篇文章主要介紹了Bootstarp風格的toggle效果分享的相關資料,需要的朋友可以參考下
    2016-02-02
  • JavaScript實現驗證碼案例

    JavaScript實現驗證碼案例

    這篇文章主要為大家詳細介紹了JavaScript實現驗證碼案例,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-10-10

最新評論

乌兰浩特市| 红原县| 中山市| 阜城县| 新密市| 绥中县| 威海市| 寿阳县| 临桂县| 江都市| 扬州市| 定远县| 上虞市| 个旧市| 陆丰市| 北辰区| 土默特左旗| 双柏县| 富源县| 南华县| 隆安县| 澄江县| 邓州市| 四川省| 石门县| 习水县| 获嘉县| 枣阳市| 陆川县| 增城市| 海门市| 洪泽县| 且末县| 山阴县| 兴业县| 武清区| 本溪| 河间市| 如皋市| 眉山市| 阜宁县|