jQuery+CSS怎樣實現(xiàn)前端網(wǎng)頁加載進度條的三種方式-創(chuàng)新互聯(lián)

這篇“jQuery+CSS怎樣實現(xiàn)前端網(wǎng)頁加載進度條的三種方式”文章,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要參考一下,對于“jQuery+CSS怎樣實現(xiàn)前端網(wǎng)頁加載進度條的三種方式”,小編整理了以下知識點,請大家跟著小編的步伐一步一步的慢慢理解,接下來就讓我們進入主題吧。

創(chuàng)新互聯(lián)長期為近1000家客戶提供的網(wǎng)站建設(shè)服務(wù),團隊從業(yè)經(jīng)驗10年,關(guān)注不同地域、不同群體,并針對不同對象提供差異化的產(chǎn)品和服務(wù);打造開放共贏平臺,與合作伙伴共同營造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為武宣企業(yè)提供專業(yè)的成都網(wǎng)站制作、成都網(wǎng)站建設(shè)、外貿(mào)營銷網(wǎng)站建設(shè),武宣網(wǎng)站改版等技術(shù)服務(wù)。擁有十多年豐富建站經(jīng)驗和眾多成功案例,為您定制開發(fā)。

css是什么意思

css是一種用來表現(xiàn)HTML或XML等文件樣式的計算機語言,主要是用來設(shè)計網(wǎng)頁的樣式,使網(wǎng)頁更加美化。它也是一種定義樣式結(jié)構(gòu)如字體、顏色、位置等的語言,并且css樣式可以直接存儲于HTML網(wǎng)頁或者單獨的樣式單文件中,而樣式規(guī)則的優(yōu)先級由css根據(jù)這個層次結(jié)構(gòu)決定,從而實現(xiàn)級聯(lián)效果,發(fā)展至今,css不僅能裝飾網(wǎng)頁,也可以配合各種腳本對于網(wǎng)頁進行格式化。

前端網(wǎng)頁加載進度條的實現(xiàn)有三種方式,看自己需求:

一、頂部進度條

在html代碼中間插入jq代碼  執(zhí)行動畫。頁面加載到哪部分,進度條就會相應(yīng)的向前走多少

當(dāng)全部加載完成后將loading進度條模塊隱藏

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script src="jquery.min.js"></script>
    <title>頂部進度條</title>
    <style>
        .loading {position: fixed;top: 0;left: 0; width: 100%; height: 100%; background-color: #fff;}
        .pic {width: 0;height: 10px;background-color: #c33;border-radius: 5px;}
    </style>
</head>
<body>
    <div>
        <div></div>
    </div>
    <header>
        <img src="http://file02.16sucai.com/d/file/2015/0128/8b0f093a8edea9f7e7458406f19098af.jpg" alt="">
        <img src="http://img12.3lian.com/gaoqing02/02/93/37.jpg" alt="">
    </header>
    <script>
        $(".loading .pic").animate({width: "20%"},100);
    </script>
    <section>
        <img src="http://g.hiphotos.baidu.com/zhidao/pic/item/c83d70cf3bc79f3d6e7bf85db8a1cd11738b29c0.jpg" alt="">
        <img src="http://big5.wallcoo.com/photograph/summer_feeling/images/%5Bwallcoo.com%5D_summer_feeling_234217.jpg" alt="">
    </section>
    <script>
        $(".loading .pic").animate({width: "40%"},100);
    </script>
    <section>
        <img src="http://cdn.duitang.com/uploads/item/201409/08/20140908130732_kVXzh.jpeg" alt="">
        <img src="http://file02.16sucai.com/d/file/2014/1006/e94e4f70870be76a018dff428306c5a3.jpg" alt="">
    </section>
    <script>
        $(".loading .pic").animate({width: "60%"},100);
    </script>
    <section>
        <img src="http://b-ssl.duitang.com/uploads/item/201703/01/20170301163305_sCd8j.gif" alt="">
    </section>
    <script>
        $(".loading .pic").animate({width: "80%"},100);
    </script>
    <footer>
        <img src="http://img.51ztzj.com/upload/image/20130417/201304172007_670x419.jpg" alt="">
        <img src="http://img0.imgtn.bdimg.com/it/u=1618007397,4183425847&fm=26&gp=0.jpg" alt="">
    </footer>
    <script>
        $(".loading .pic").animate({width: "100%"},100, function() {
            $(".loading").fadeOut();
        });
    </script>
</body>
</html>

二、直接在頁面插入關(guān)于加載的動態(tài)圖,頁面加載完再隱藏掉

關(guān)于圖片可以在這個網(wǎng)站找:https://loading.io/  可以根據(jù)自己的需求調(diào)樣式

jQuery+CSS怎樣實現(xiàn)前端網(wǎng)頁加載進度條的三種方式

當(dāng)然,如果想自己寫也可以,下面是博主自己用css3寫的一個小動畫

jQuery+CSS怎樣實現(xiàn)前端網(wǎng)頁加載進度條的三種方式jQuery+CSS怎樣實現(xiàn)前端網(wǎng)頁加載進度條的三種方式

代碼如下

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>css3動畫進度條</title>
    <style>
        .loading {position: fixed;top:0;left:0;width: 100%; height: 100%;background-color: #fff;}
        .pic {position: absolute;top: 0;bottom: 0;left: 0;right: 0;margin: auto;width: 100px;height:40px;}
        .pic i {float:left;margin: 0 2px;width: 6px;height: 30px;background-color: indigo;transform: scaleY(0.4);animation: load 1.2s infinite;}
        .pic i:nth-child(2){-webkit-animation-delay: 0.1s;animation-delay: 0.1s;}
        .pic i:nth-child(3){-webkit-animation-delay: 0.2s;animation-delay: 0.2s;}
        .pic i:nth-child(4){-webkit-animation-delay: 0.3s;animation-delay: 0.3s;}
        .pic i:nth-child(5){-webkit-animation-delay: 0.4s;animation-delay: 0.4s;}
        .pic i:nth-child(6){-webkit-animation-delay: 0.5s;animation-delay: 0.5s;}
        @-webkit-keyframes load {
            0%,40%,100%{-webkit-transform: scaleY(0.4); transform: scaleY(0.4)}
            20%{-webkit-transform: scaleY(1); transform: scaleY(1)}
        }
        @keyframes load {
            0%,40%,100%{-webkit-transform: scaleY(0.4); transform: scaleY(0.4)}
            20%{-webkit-transform: scaleY(1); transform: scaleY(1)}
        }
    </style>
    <script src="jquery.min.js"></script>
    <script>
        document.onreadystatechange = function() {  // 頁面狀態(tài)發(fā)生改變時觸發(fā)
            if(document.readyState == "complete") {  // 頁面加載完成時隱藏
                $(".loading").fadeOut();
            }
        }
    </script>
</head>
<body>
    <div>
        <div>
            <i></i>
            <i></i>
            <i></i>
            <i></i>
            <i></i>
            <i></i>
        </div>
    </div>
    <img src="http://file02.16sucai.com/d/file/2015/0128/8b0f093a8edea9f7e7458406f19098af.jpg" alt="">
    <img src="http://img12.3lian.com/gaoqing02/02/93/37.jpg" alt="">
    <img src="http://g.hiphotos.baidu.com/zhidao/pic/item/c83d70cf3bc79f3d6e7bf85db8a1cd11738b29c0.jpg" alt="">
    <img src="http://big5.wallcoo.com/photograph/summer_feeling/images/%5Bwallcoo.com%5D_summer_feeling_234217.jpg" alt="">
    <img src="http://cdn.duitang.com/uploads/item/201409/08/20140908130732_kVXzh.jpeg" alt="">
    <img src="http://file02.16sucai.com/d/file/2014/1006/e94e4f70870be76a018dff428306c5a3.jpg" alt="">
    <img src="http://b-ssl.duitang.com/uploads/item/201703/01/20170301163305_sCd8j.gif" alt="">
    <img src="http://img.51ztzj.com/upload/image/20130417/201304172007_670x419.jpg" alt="">
    <img src="http://img0.imgtn.bdimg.com/it/u=1618007397,4183425847&fm=26&gp=0.jpg" alt="">
</body>
</html>

三、實時獲取數(shù)據(jù)的進度條(百分比)

jQuery+CSS怎樣實現(xiàn)前端網(wǎng)頁加載進度條的三種方式

代碼如下

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>百分比進度條</title>
    <style>
        .loading {position: fixed;top:0;left:0;width: 100%; height: 100%;background-color: #fff;}
        .pic {position: absolute;top: 0;bottom: 0;left: 0;right: 0;margin: auto;width: 100px;height:100px;line-height: 55px;text-align: center;font-size: 22px;}
        .pic span {display: inline-block;position: absolute;top: 10px;left: 10px;width: 80px;height: 80px;border-radius: 50%;box-shadow: 0 3px 0 #999;
                -webkit-animation: move 1s infinite linear;animation: move 1s infinite linear;}
        @-webkit-keyframes move {
            0%{-webkit-transform: rotate(0deg);transform: rotate(0deg);}
            100%{-webkit-transform: rotate(360deg);transform: rotate(360deg);}
        }
        @keyframes move {
            0%{-webkit-transform: rotate(0deg);transform: rotate(0deg);}
            100%{-webkit-transform: rotate(360deg);transform: rotate(360deg);}
        }
    </style>
    <script src="jquery.min.js"></script>
    <script>
        $(function() {
            var img = $("img"); // 獲取所有的img元素
            var num = 0;  // 用來存儲已加載的圖片個數(shù)
            img.each(function(i) {  // 遍歷所有圖片
                var oImg = new Image();
                oImg.onload = function() { // onload 圖片加載完成后執(zhí)行
                    num++;
                    $(".pic p").html(parseInt(num / img.length * 100) + '%');
                    if(num >= img.length) {
                        $(".loading").fadeOut(); // 頁面加載完成后隱藏
                    }
                }
                oImg.src = img[i].src;
            })
        })
    </script>
</head>
<body>
    <div>
        <div>
            <span></span>
            <p>0%</p>
        </div>
    </div>
    <img src="http://file02.16sucai.com/d/file/2015/0128/8b0f093a8edea9f7e7458406f19098af.jpg" alt="">
    <img src="http://img12.3lian.com/gaoqing02/02/93/37.jpg" alt="">
    <img src="http://g.hiphotos.baidu.com/zhidao/pic/item/c83d70cf3bc79f3d6e7bf85db8a1cd11738b29c0.jpg" alt="">
    <img src="http://big5.wallcoo.com/photograph/summer_feeling/images/%5Bwallcoo.com%5D_summer_feeling_234217.jpg" alt="">
    <img src="http://cdn.duitang.com/uploads/item/201409/08/20140908130732_kVXzh.jpeg" alt="">
    <img src="http://file02.16sucai.com/d/file/2014/1006/e94e4f70870be76a018dff428306c5a3.jpg" alt="">
    <img src="http://b-ssl.duitang.com/uploads/item/201703/01/20170301163305_sCd8j.gif" alt="">
    <img src="http://img.51ztzj.com/upload/image/20130417/201304172007_670x419.jpg" alt="">
    <img src="http://img0.imgtn.bdimg.com/it/u=1618007397,4183425847&fm=26&gp=0.jpg" alt="">
</body>
</html>

以上是“jQuery+CSS怎樣實現(xiàn)前端網(wǎng)頁加載進度條的三種方式”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!

當(dāng)前題目:jQuery+CSS怎樣實現(xiàn)前端網(wǎng)頁加載進度條的三種方式-創(chuàng)新互聯(lián)
當(dāng)前網(wǎng)址:http://bm7419.com/article44/dcoghe.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站建設(shè)、電子商務(wù)、網(wǎng)站建設(shè)、網(wǎng)站維護Google、靜態(tài)網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都做網(wǎng)站