js頁面加載進度條(這個就比較正式了,改改時間就完事兒)


不廢話,直接上代碼

思路不難,就是一個animate方法配合隨機數

duration內個三秒鍾,是自定義的,可以改成頁面加載時間,這樣就完美了

 

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>無標題文檔</title>
<script src="js/jquery-1.8.3.min.js"></script>
<style>
body { margin: 0; }
#progress { position: fixed; height: 2px; background: #2085c5; transition: opacity 500ms linear }
#progress.done { opacity: 0 }
#progress span { position: absolute; height: 2px; -webkit-box-shadow: #2085c5 1px 0 6px 1px; -webkit-border-radius: 100%; opacity: 1; width: 150px; right: -10px; -webkit-animation: pulse 2s ease-out 0s infinite; }
@-webkit-keyframes pulse {  30% {
 opacity:.6
}
 60% {
 opacity:0;
}
 100% {
 opacity:.6
}
}
</style>
</head>

<body>
<div id="progress"><span></span></div>
<script>
$({property: 0}).animate({property: 100}, {
    duration: 3000,
    step: function() {
        var percentage = Math.round(this.property);

        $('#progress').css('width',  percentage+"%");
        if(percentage == 100) {
            $("#progress").addClass("done");//完成,隱藏進度條
        }
    }
});
</script>
</body>
</html>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM