javascript - 带有不可见层的预加载器覆盖页面

标签 javascript jquery html css

我已经创建了一个预加载器,除了当它消失时它仍然可以作为一个覆盖页面上所有内容的不可见层之外工作正常。所以链接之类的内容都不能点击。如何解决这个问题但仍然保留动画?

Codepen

<body>
  <div id="preloader_wrap">
    <div class="section" id="right_sect">

    </div>

    <div class="section" id="left_sect">

    </div>

    <div id="content">
      <div id="img">

      </div>

      <div id="loading_bar">
        <div></div>
      </div>
    </div>
  </div>

  <header>
    <ul>
      <li><a href="">Link</a></li>
      <li><a href="">Link</a></li>
      <li><a href="">Link</a></li>
    </ul>
  </header>
</body>

<script
  src="https://code.jquery.com/jquery-3.2.1.min.js"
  integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
  crossorigin="anonymous"></script>

CSS:

*{
  margin: 0; 
  padding: 0;
}

body{
  background-color: #666666;
  width: 100%;
}

#preloader_wrap{
  z-index: 1010;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
}

.section{
  position: fixed;
  width: 50%; 
  height: 100%;
  background-color: black;
  top: 0;
  transition: width 1s;
}

#left_sect{
  left: 0;
}

#right_sect{
  right: 0;
}

#content{
  position: relative;
  margin: 100px auto 0 auto;
  width: 600px;
  transition: all 1s;
}

#img{
  height: 200px;
  width: 300px;
  background-color: red;
  margin: 0 auto;
}

#loading_bar{
  height: 50px;
  width: 50px;
  margin: 30px auto;
}

#loading_bar div{
  height: 100%;
  width: 100%;
  border-bottom: 4px solid #ffffff;
  border-left: 4px solid transparent;
  border-radius: 100%;
  animation: spin 0.9s linear infinite;
  -webkit-animation: spin 0.9s linear infinite;
  -moz-animation: spin 0.9s linear infinite;
  -o-animation: spin 0.9s linear infinite;
}

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

body.loaded .section{
  width: 0;
}

body.loaded #content{
  opacity: 0;
}

header{
  width: 100%;
  height: 75px;
  background-color: blue;
  position: fixed;
  top: 0;
  z-index: 1000;
}

ul{
  list-style-type: none;
  margin: 10px auto;
  width: 300px;
}

ul li{
  display: inline-block;
  font-size: 40px;
}

ul li a{
  color: white;
}

JS:

$(document).ready(function() {

    setTimeout(function(){
        $('body').addClass('loaded');
    }, 2000);

});

最佳答案

将您的脚本更改为...

$(document).ready(function() {

    setTimeout(function(){
        $('body').addClass('loaded');
        $('#preloader_wrap').remove();
    }, 2000);

});

这将在页面加载后完全删除图层。

关于javascript - 带有不可见层的预加载器覆盖页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43468323/

相关文章:

ios - 在 iOS Safari 上播放 WAV 文件

html - Bootstrap 表的 IE11 Flex 问题

javascript - 使用 Chartist.js 在条形图中显示条形内的文本

jquery - Bootstrap 轮播 - 链接到特定幻灯片

c# - 在 asp.net mvc c# 中将钱格式化为货币

javascript - AngularJS - 在选择标签中使用 ng-repeat 添加了额外的空白选项

html - 用线填充空白

javascript - angular.js 错误地解析整数

javascript - 为什么 saga 函数第二次不接受请求?

javascript - 为什么不通过闭包定义这个变量?