JavaScript實現簡單進度條

來源:互聯網
上載者:User
      好久沒更新部落格了,換了工作環境,比較忙,月底了一篇文章都沒有更新。這裡簡單實現一個功能。Javascript實習進度條。文本借鑒於:http://blog.csdn.net/2004v2004/archive/2008/02/19/2106689.aspx,在次基礎上通過Javascript來實現這個功能。歡迎提出意見。可以通過點擊上面的按鈕來看進度條的效果。點擊此處展開代碼:

點擊展開

Code
 <script language="javascript">
        function SetPorgressBar(pos)
        {
            //設定進度條置中
            var screenHeight = document.body.offsetHeight;
            var screenWidth =document.body.offsetWidth;
            ProgressBarSide.style.width = Math.round(screenWidth / 2);
            ProgressBarSide.style.left = Math.round(screenWidth / 4);
            ProgressBarSide.style.top = Math.round(screenHeight / 2);
            ProgressBarSide.style.height = "100px";
            ProgressBarSide.style.display = "";
             
            //設定進度條百分比                       
            ProgressBar.style.width = pos + "%";
            ProgressText.innerHTML = pos + "%";
        }

        //完成後隱藏進度條
        function SetCompleted()
        {       
            ProgressBarSide.style.display = "none";
        }
    </script> Code
 <script>
    var i=0;
    var fun;
    function myRefresh()
    {     
        SetPorgressBar(i);
        i++;
        if(i<100)
        {           
           fun=setTimeout("myRefresh()",100);
        }
        else
        {
            SetCompleted();
            window.clearTimeout(fun);
            alert("載入完成");   
            i=0;       
        }
    }    
    window.onload=myRefresh;
    </script> Code
 <div id="ProgressBarSide" style="position: absolute; height: 100px; width: 100px; color: Silver;
        border-width: 1px; border-style: Solid; display: none">
        <div id="ProgressBar" style=" font-size:larger; position: absolute; height: 100px; width: 0%; background-color: #3366FF">
        </div>
        <div id="ProgressText" style="position: absolute; height: 100px; width: 100%;text-align:center; font-size:80px;">
        qqqq
        </div>
    </div>
    <div>
        <input onclick="javascript:myRefresh();" type="button" value="重新載入進度條"></div>
    <div>
        <input onclick="javascript:window.location.reload();" type="button" value="重新載入頁面">
    </div> Best Regards,Charles Chenmsn: gotosunny@msn.com   

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.