草鞋

          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>

          主站蜘蛛池模板: 扬州市| 浪卡子县| 驻马店市| 霍山县| 珲春市| 铜山县| 嘉祥县| 迁西县| 滨州市| 施秉县| 五莲县| 河池市| 同德县| 图片| 鹤岗市| 定陶县| 庐江县| 三门县| 天台县| 河曲县| 疏附县| 石河子市| 定边县| 云阳县| 英山县| 浦江县| 顺义区| 大渡口区| 石台县| 安新县| 南江县| 深州市| 武胜县| 阜平县| 临泉县| 治县。| 神农架林区| 临猗县| 福泉市| 德令哈市| 舟山市|