1. 程式人生 > >進入頁面載入進度條

進入頁面載入進度條

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>進度條</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        #progress{
            width: 100%;
            height: 30px;
            background: #00bc12;
        }
        #bar{
            width: 1%;
            height: 30px;
            margin-top: 1px;
            background: #e4b4e4;
        }
    </style>
</head>
<body>
    <div id="progress">
        <div id="bar"></div>
    </div>
    <div><h3 id="text-progress">0%</h3></div>
</body>
<script>
    function action(){
        var iSpeed=1;
        obj=setInterval(function(){
            iSpeed+=1;
            if(iSpeed>=100){    // 設定達到多少進度後停止
                clearInterval(obj); 
                }
            bar.style.width=iSpeed+'%';
            document.getElementById('text-progress').innerHTML=iSpeed+'%';            
        },100);
    }
    action();
</script>
</html>

效果圖在這裡插入圖片描述