繁体   English   中英

预加载器不会在加载时停止

[英]Preloader doesn't stop on load

我正在尝试在页面加载后停止预加载器。

假设我们采用下面的预加载器。

CSS:

body {
  background: #eaecfa;
}

.loader {
  width: 250px;
  height: 50px;
  line-height: 50px;
  text-align: center;
  position: absolute;
  top: 50%;
  left: 50%;
  -webkit-transform: translate(-50%, -50%);
          transform: translate(-50%, -50%);
  font-family: helvetica, arial, sans-serif;
  text-transform: uppercase;
  font-weight: 900;
  color: #ce4233;
  letter-spacing: 0.2em;
}
.loader::before, .loader::after {
  content: "";
  display: block;
  width: 15px;
  height: 15px;
  background: #ce4233;
  position: absolute;
  -webkit-animation: load .7s infinite alternate ease-in-out;
          animation: load .7s infinite alternate ease-in-out;
}
.loader::before {
  top: 0;
}
.loader::after {
  bottom: 0;
}

@-webkit-keyframes load {
  0% {
    left: 0;
    height: 30px;
    width: 15px;
  }
  50% {
    height: 8px;
    width: 40px;
  }
  100% {
    left: 235px;
    height: 30px;
    width: 15px;
  }
}

@keyframes load {
  0% {
    left: 0;
    height: 30px;
    width: 15px;
  }
  50% {
    height: 8px;
    width: 40px;
  }
  100% {
    left: 235px;
    height: 30px;
    width: 15px;
  }
}

HTML:

<div class="loader">Loading...</div>

为什么以下JS代码有效,即我收到警报:

$(document).ready(function(){
  $(window).load(function(){
    alert("This can run");
  });
  })

具有更改行的相同代码不会停止预加载器?

$(document).ready(function(){
  $(window).load(function(){
    $("loader").remove();
  });
  })

我是一个完整的网络开发新手,但是在这里尝试了很多其他的答案,但我无法让它们中的任何一个起作用。

你错过了一个. $("loader").remove() :)

$(document).ready(function(){
  $(window).load(function(){
    $(".loader").remove();
  });
  })

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM