草鞋

          Blog grass shoes
          posts - 1, comments - 4, trackbacks - 0, articles - 27
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          JS進度條一

          Posted on 2007-10-23 09:48 草 鞋 閱讀(276) 評論(0)  編輯  收藏 所屬分類: JavaScript

          <script>
          if(window.ActiveXObject){
           document.execCommand("BackgroundImageCache",false,true);
          }

          function ProcessBar(){
             this.width = 256;
             this.height = 18;
             this.top = 0;
             this.left = 0;
             this.backImg = "process_back.gif";
             this.foreImg = "process.gif";
             this.backDiv = document.createElement("div");
             this.foreDiv = document.createElement("div");
             this.fontDiv = document.createElement("div");

             this.isMoving = false;
             this.nowLength = 0;
             this.moveInterval = 100;
             this.moveRange = 1;
             this.timer;
             this.isHide = true; 

             ProcessBar.nowObj = this;

             this.init = function(){
                  this.foreDiv.style.backgroundImage = "url(" + this.foreImg + ")";
            this.foreDiv.style.backgroundRepeat = "no-repeat";
            this.foreDiv.style.position = "absolute";
            this.foreDiv.style.width = this.nowLength;
            this.foreDiv.style.height = this.height;
            this.foreDiv.style.top = 0;
            this.foreDiv.style.left = 0;
            
            this.fontDiv.style.background = "transparent";
            this.fontDiv.style.position = "absolute";
            this.fontDiv.style.width = this.width;
            this.fontDiv.style.height = this.height;
            this.fontDiv.style.top = 2;
            this.fontDiv.style.left = 0;
            this.fontDiv.style.textAlign = "center";
            this.fontDiv.style.fontSize = "13px";
            this.fontDiv.appendChild(document.createTextNode(" "));

            this.backDiv.style.backgroundImage = "url(" + this.backImg + ")";
            this.backDiv.style.backgroundRepeat = "no-repeat";
            this.backDiv.style.position = "absolute";
            this.backDiv.style.width = this.width;
            this.backDiv.style.height = this.height;
            this.backDiv.style.top = this.top;
            this.backDiv.style.left = this.left;

            this.backDiv.appendChild(this.foreDiv);
            this.backDiv.appendChild(this.fontDiv);

            document.body.appendChild(this.backDiv);

            this.backDiv.style.visibility = "";
            this.isHide = false;
             }

             this.changeMode = function(){
            this.isMoving = !this.isMoving;
            
            if(this.isMoving){
             this.timer = window.setInterval("ProcessBar.nowObj.moving()", this.moveInterval);
            }else{
             window.clearInterval(this.timer);
            }
             }

             this.moving = function(range){
            range = range || ProcessBar.nowObj.moveRange;
                  ProcessBar.nowObj.nowLength += range;
            ProcessBar.nowObj.foreDiv.style.width = ProcessBar.nowObj.nowLength;

            ProcessBar.nowObj.fontDiv.firstChild.data = Math.ceil((ProcessBar.nowObj.nowLength/ProcessBar.nowObj.width)*100) + "%";

            if(ProcessBar.nowObj.nowLength >= ProcessBar.nowObj.width){
             window.clearInterval(ProcessBar.nowObj.timer);
             ProcessBar.nowObj.fontDiv.firstChild.data = "Complete!";
            }
             }

             this.moveTo = function(pts){
            var isPercent = false;
            var val = pts;
            if(!pts) return;

            if(isNaN(pts)){
             pts = Math.round(parseInt(pts.replace(/\%/,"")) * ProcessBar.nowObj.width/100);
             isPercent = true;
            }
            
            if(pts < 0 || pts > ProcessBar.nowObj.width) return;

            ProcessBar.nowObj.nowLength = pts;
            ProcessBar.nowObj.foreDiv.style.width = ProcessBar.nowObj.nowLength;
            ProcessBar.nowObj.fontDiv.firstChild.data = isPercent?val:Math.ceil((ProcessBar.nowObj.nowLength/ProcessBar.nowObj.width)*100) + "%";
             }

             this.hide = function(){
            this.isHide = true;
            this.backDiv.style.visibility = "hidden";
             }

             this.show = function(){
            this.isHide = false;
            this.backDiv.style.visibility = "";
             }
          }
          </script>
          <body>
          <input type="button" value="start" onclick="processBar.changeMode();if(processBar.isMoving){this.value='Stop';}else{this.value='Start';}">
          <input type="button"  value="加速" onclick="processBar.moveRange++;">
          <input type="button"  value="顯示" onclick="if(processBar.isHide) processBar.show();else processBar.hide();">
          <input type="button"  value="Go" onclick="processBar.moveTo(sel.value==2?val.value:val.value+'%');"><input id="val" size="2"><select id="sel"><option  value="1">%</option><option value="2">px</option></select>
          </body>
          <script>
          var processBar = new ProcessBar();
          processBar.width=327
          processBar.backImg = "http://screenprint2007.cpp114.com/UserFiles/20070414161906093.jpg";
          processBar.foreImg = "http://screenprint2007.cpp114.com/UserFiles/20070414161919171.jpg";
          processBar.top = 100;
          processBar.left = 20;
          processBar.init();

          </script>

          主站蜘蛛池模板: 内乡县| 武胜县| 沂南县| 东方市| 安仁县| 榆社县| 府谷县| 兴山县| 宣化县| 岳阳县| 原平市| 巩义市| 临泽县| 威宁| 中西区| 侯马市| 平湖市| 都昌县| 湖口县| 孙吴县| 调兵山市| 洪泽县| 南通市| 商都县| 溆浦县| 城口县| 田阳县| 焦作市| 收藏| 威远县| 西平县| 吉林省| 色达县| 和龙市| 洪洞县| 连城县| 德阳市| 肃北| 垦利县| 同心县| 方正县|