美文网首页
页面加载小案例

页面加载小案例

作者: boyiis | 来源:发表于2018-11-08 11:19 被阅读0次

将下面代码直接拷贝到.html文件中,浏览器打开就可以看到效果了,这只是个演示页面,所以没有做兼容

<!DOCTYPE html>
<html lang="en">

<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 {
            width: 100%;
            height: 100%;
            position: fixed;
            top: 0;
            left: 0;
            z-index: 100;
            background: #ffffff;
        }

        .loading .pic {
            width: 50px;
            height: 50px;
            position: absolute;
            top: 0;
            left: 0;
            bottom: 0;
            right: 0;
            margin: auto;
        }
        .loading .pic i{
            display: block;
            float: left;
            width: 6px;
            height: 50px;
            background: #399;
            margin: 0 2px;
            transform: scaleY(0.4);
            animation: load 1.2s infinite;
        }

        .loading .pic i:nth-child(1){}
        .loading .pic i:nth-child(2){animation-delay: 0.1s}
        .loading .pic i:nth-child(3){animation-delay: 0.2s}
        .loading .pic i:nth-child(4){animation-delay: 0.3s}
        .loading .pic i:nth-child(5){animation-delay: 0.4s}

        @keyframes load{
            0%, 40%, 100%{
                transform: scaleY(0.4)
            }
            20% {
                transform: scaleY(1)
            }
        }
    </style>
</head>

<body>
    <img src="http://h.hiphotos.baidu.com/image/pic/item/03087bf40ad162d92dc06e711cdfa9ec8a13cdb5.jpg" alt="">
    <img src="http://h.hiphotos.baidu.com/image/pic/item/d1160924ab18972b132c39acebcd7b899e510a45.jpg" alt="">
    <img src="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1541652300993&di=1dd9e2513157ecd41aceed76bc74c970&imgtype=0&src=http%3A%2F%2Ft1.niutuku.com%2F960%2F30%2F30-416481.jpg"
        alt="">

    <div class="loading">
        <div class="pic">
            <i></i>
            <i></i>
            <i></i>
            <i></i>
            <i></i>
        </div>
    </div>

    <script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
    <script>
        //实时加载
        document.onreadystatechange = function(){
            if("complete" === document.readyState){
                $(".loading").fadeOut();
            }
        }
        //默认3秒隐藏
        $(function(){
            // setTimeout(function(){
            //     $(".loading").fadeOut();
            // }, 3000)
        })

    </script>
</body>

</html>

加载带进度

<!DOCTYPE html>
<html lang="en">

<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>
        * {
            padding: 0;
            margin: 0;
        }

        .loading {
            width: 100%;
            height: 100%;
            position: fixed;
            top: 0;
            left: 0;
            z-index: 100;
            background: #ffffff;
        }

        .loading .pic {
            width: 100px;
            height: 100px;
            position: absolute;
            top: 0;
            left: 0;
            bottom: 0;
            right: 0;
            margin: auto;
            font-size: 20px;
            text-align: center;
            line-height: 100px;
        }

        .loading .pic span {
            display: block;
            width: 80px;
            height: 80px;
            position: absolute;
            top: 10px;
            left: 10px;
            border-radius: 50%;
            box-shadow: 0 3px 0 #666666;
            animation: rotate 1s infinite linear;
        }

        @keyframes rotate {
            0% {
                transform: rotate(0deg);
            }
            100% {
                transform: rotate(360deg);
            }
        }
    </style>
</head>

<body>

    <header>
        <img src="http://h.hiphotos.baidu.com/image/pic/item/03087bf40ad162d92dc06e711cdfa9ec8a13cdb5.jpg" alt="">
    </header>
    <section class="banner">
        <img src="http://h.hiphotos.baidu.com/image/pic/item/d1160924ab18972b132c39acebcd7b899e510a45.jpg" alt="">
    </section>
    <section class="about">
        <img src="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1541652300993&di=1dd9e2513157ecd41aceed76bc74c970&imgtype=0&src=http%3A%2F%2Ft1.niutuku.com%2F960%2F30%2F30-416481.jpg"
            alt="">
    </section>
    <section class="pro">
        <img src="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1541652300993&di=1dd9e2513157ecd41aceed76bc74c970&imgtype=0&src=http%3A%2F%2Ft1.niutuku.com%2F960%2F30%2F30-416481.jpg"
            alt="">
    </section>
    <section class="news">
        <img src="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1541652300993&di=1dd9e2513157ecd41aceed76bc74c970&imgtype=0&src=http%3A%2F%2Ft1.niutuku.com%2F960%2F30%2F30-416481.jpg"
            alt="">
    </section>
    <footer>
        <img src="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1541652300993&di=1dd9e2513157ecd41aceed76bc74c970&imgtype=0&src=http%3A%2F%2Ft1.niutuku.com%2F960%2F30%2F30-416481.jpg"
            alt="">
    </footer>

    <div class="loading">
        <div class="pic">
            <span></span>
            <b>0%</b>
        </div>
    </div>

    <script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
    <script>
 
        $(function () {
            var img = $("img");
            var num = 0;

            img.each(function(i){
                var oImg = new Image();
                oImg.onload = function(){
                    console.log(i);
                    console.log(num);
                    oImg.onload = null;
                    num ++;
                    console.log(i);
                    console.log(num);
                    $(".loading b").html(parseInt(num/$("img").size()*100) + "%");
                    
                    if(num >= i){
                        $(".loading").fadeOut();
                    }
                }
                oImg.src = img[i].src;
            });

            var img = new Image();
            
        })

    </script>
</body>

</html>
<!DOCTYPE html>
<html lang="en">

<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>
    <script src="http://cdn.bootcss.com/pace/1.0.2/pace.min.js"></script>
    <script>    
        {
            function getElementsByClass(key) {
                var arr = new Array();
                var tags = document.getElementsByTagName("*");
                for (var i = 0; i < tags.length; i++) {
                    if (tags[i].className.match(new RegExp('(\\s|^)' + key + '(\\s|$)'))) {
                        arr.push(tags[i]);
                    }
                }
                return arr;
            }
            var timer = window.setInterval(function () {
                var el = getElementsByClass('pace');
                if (el.length > 0) {
                    var a = document.createElement('div');
                    a.setAttribute('class', 'spinner');
                    var b = document.createElement('div');
                    b.setAttribute('class', 'spinner-icon');
                    el[0].appendChild(a);
                    a.appendChild(b);
                    window.clearInterval(timer);
                }
            }, 3);
        }    
    </script>
    <style>
        .pace .spinner {
            position: fixed;
            top: 15px;
            right: 15px;
            z-index: 2000;
            display: block;
        }

        .pace .spinner-icon {
            width: 18px;
            height: 18px;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            border: solid 2px transparent;
            border-top-color: #2299dd;
            border-left-color: #2299dd;
            border-radius: 50%;
            -webkit-animation: nprogress-spinner .4s linear infinite;
            animation: nprogress-spinner .4s linear infinite;
        }

        @-webkit-keyframes nprogress-spinner {
            0% {
                -webkit-transform: rotate(0deg);
                transform: rotate(0deg);
            }
            100% {
                -webkit-transform: rotate(360deg);
                transform: rotate(360deg);
            }
        }

        @keyframes nprogress-spinner {
            0% {
                -webkit-transform: rotate(0deg);
                transform: rotate(0deg);
            }
            100% {
                -webkit-transform: rotate(360deg);
                transform: rotate(360deg);
            }
        }

        @keyframes fadeOut {
            from {
                opacity: 1;
            }
            to {
                opacity: 0;
            }
        }

        .pace {
            -webkit-pointer-events: none;
            pointer-events: none;
            -webkit-user-select: none;
            -moz-user-select: none;
            user-select: none;
            -webkit-transition: opacity 0.8s ease-in-out;
            -moz-transition: opacity 0.8s ease-in-out;
            -o-transition: opacity 0.8s ease-in-out;
            transition: opacity 0.8s ease-in-out;
        }

        .pace-inactive {
            opacity: 0;
            filter: alpha(opacity=0);
        }

        .pace .pace-progress {
            background: #2299dd;
            position: fixed;
            z-index: 2000;
            top: 0;
            right: 100%;
            width: 100%;
            height: 3px;
            box-shadow: 0 0 3px #2299dd;
        }
    </style>
    <!-- 右上角三角 
<link href="http://cdn.bootcss.com/pace/1.0.2/themes/black/pace-theme-corner-indicator.min.css" rel="stylesheet">
-->
</head>

<body>

    <header>
        <img src="http://h.hiphotos.baidu.com/image/pic/item/03087bf40ad162d92dc06e711cdfa9ec8a13cdb5.jpg" alt="">

    </header>
    <section class="banner">
        <img src="http://h.hiphotos.baidu.com/image/pic/item/d1160924ab18972b132c39acebcd7b899e510a45.jpg" alt="">

    </section>
    <section class="about">
        <img src="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1541652300993&di=1dd9e2513157ecd41aceed76bc74c970&imgtype=0&src=http%3A%2F%2Ft1.niutuku.com%2F960%2F30%2F30-416481.jpg"
            alt="">
    </section>
    <section class="pro">
        <img src="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1541652300993&di=1dd9e2513157ecd41aceed76bc74c970&imgtype=0&src=http%3A%2F%2Ft1.niutuku.com%2F960%2F30%2F30-416481.jpg"
            alt="">
    </section>
    <section class="news">
        <img src="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1541652300993&di=1dd9e2513157ecd41aceed76bc74c970&imgtype=0&src=http%3A%2F%2Ft1.niutuku.com%2F960%2F30%2F30-416481.jpg"
            alt="">
    </section>
    <footer>
        <img src="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1541652300993&di=1dd9e2513157ecd41aceed76bc74c970&imgtype=0&src=http%3A%2F%2Ft1.niutuku.com%2F960%2F30%2F30-416481.jpg"
            alt="">
    </footer>

</body>

</html>

相关文章

  • 页面加载小案例

    将下面代码直接拷贝到.html文件中,浏览器打开就可以看到效果了,这只是个演示页面,所以没有做兼容 加载带进度

  • Day19

    完成商品展示功能 案例实现 案例1-展示分类信息 需求描述:加载页面时,请求数据库查找分类信息,返回页面展示 技术...

  • day12-升级登录案例

    升级登录案例(ajax) ajax:异步的javascript在不重新加载页面的情况下,对页面进行局部刷新。 1、...

  • H5案例分析 | 圣诞焕境之旅

    【案例】圣诞焕境之旅 【出品】恒隆广场·上海 【类型】图文展示 【内容策划】 打开H5,进入加载页面,加载过后,会...

  • 使用html2canvas绘制分享微信图像

    案例如图:image.png 基本原理:页面加载完成之后用canvas进行绘制页面,页面中只有一张图片就ok了; ...

  • 1

    1.页面加载完之前执行 2.页面加载后执行 3.页面加载后执行 4.页面加载后执行

  • 生命周期

    小程序生命周期 小程序注册完成后,加载页面,触发onLoad方法。 页面载入后触发onShow方法,显示页面。 首...

  • vue页面渲染慢——类似分页加载

    案例:试卷题目一次加载完100或者更多的题目时 会导致页面渲染过慢/出现一些异常解决:可以把题目分开加载

  • 13_分页器

    分页器 使用方法: 简单小案例: 视图函数页面 html页面 HTML页面讲解: 上下页: ===========...

  • App页面加载

    1.单页面整体加载 一次性加载完页面的全部内容 2.页面分块加载 优先加载重要内容、分页加载 3.跨页面预加载 帮...

网友评论

      本文标题:页面加载小案例

      本文链接:https://www.haomeiwen.com/subject/wmnixqtx.html