草鞋

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

          JS進度條一

          Posted on 2007-10-23 09:48 草 鞋 閱讀(279) 評論(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>

          主站蜘蛛池模板: 新干县| 小金县| 黎川县| 木里| 新建县| 友谊县| 资兴市| 阿勒泰市| 景洪市| 靖安县| 和林格尔县| 芦溪县| 万山特区| 安溪县| 洛南县| 漳浦县| 潼南县| 中卫市| 莲花县| 镇江市| 二连浩特市| 视频| 长垣县| 徐州市| 阳东县| 彭泽县| 江都市| 通化市| 新密市| 南丰县| 富锦市| 宁波市| 宿迁市| 林芝县| 宁强县| 汉川市| 元谋县| 司法| 丹棱县| 长岭县| 菏泽市|