我是一个人的博客

我是一个人,只是一个人

使用HTML+CSS实现网页loading加载效果,支持定时或加载完成后隐藏

未分类 0 评 64 度
      <style>
    .loaderbg {
      background-color: #fff;
      width: 100%;
      height: 100%;
      overflow: hidden;
      position: fixed;
      left: 0;
      top: 0;
      z-index: 99999999
    }

    ::-webkit-scrollbar {
      width: 7.5px;
      height: 6px;
      background-color: #f0f0f0;
      display: none
    }

    ::-webkit-scrollbar-thumb {
      background-color: #b1b1b1;
      border-radius: 15px
    }

    ::-webkit-scrollbar-thumb:hover {
      background-color: #777
    }

    .spinner {
      position: absolute;
      top: 50%;
      left: 50%;
      margin-left: -25px;
      margin-top: -30px;
      width: 50px;
      height: 60px;
      text-align: center;
      font-size: 10px
    }

    .spinner > .double {
      background: #49a9ee;
      height: 100%;
      width: 6px;
      display: inline-block;
      -webkit-animation: stretchDelay 1.2s infinite ease-in-out;
      animation: stretchDelay 1.2s infinite ease-in-out
    }

    .spinner .rect2 {
      -webkit-animation-delay: -1.1s;
      animation-delay: -1.1s
    }

    .spinner .rect3 {
      -webkit-animation-delay: -1.0s;
      animation-delay: -1.0s
    }

    .spinner .rect4 {
      -webkit-animation-delay: -0.9s;
      animation-delay: -0.9s
    }

    .spinner .rect5 {
      -webkit-animation-delay: -0.8s;
      animation-delay: -0.8s
    }

    @-webkit-keyframes stretchDelay {

      0%,
      40%,
      100% {
        -webkit-transform: scaleY(.4)
      }

      20% {
        -webkit-transform: scaleY(1)
      }
    }

    @keyframes stretchDelay {

      0%,
      40%,
      100% {
        transform: scaleY(.4);
        -webkit-transform: scaleY(.4)
      }

      20% {
        transform: scaleY(1);
        -webkit-transform: scaleY(1)
      }
    }
  </style>
  <script src="https://code.jquery.com/jquery-3.1.1.min.js" type="application/javascript"></script>
<!--html-->
<div class="loaderbg">
  <div class="spinner">
    <div class="double rect1"></div>
    <div class="double rect2"></div>
    <div class="double rect3"></div>
    <div class="double rect4"></div>
    <div class="double rect5"></div>
  </div>
</div>
<!--end-->
<!--noscript-->
<noscript>
  <style>
    .loaderbg {
      display: none;
    }
  </style>
</noscript>
<!--end-->
<!--script-->
<script type="text/javascript">
  //页面加载完成之后隐藏loading
$(window).on('load',function(){
        $(".loaderbg").hide();
    });
  //设置页面加载3秒之后隐藏loading
  /*$(function () {
    setTimeout(function () {
      $(".loaderbg").hide();
      alert("页面加载完成啦!");
    }, 3000);
  })*/
</script>
<!--end-->

原文https://cloud.tencent.com/developer/article/2144550

cookie控制js弹窗24h弹出
快来做第一个评论的人吧~