简体   繁体   English

为什么:after元素不起作用?

[英]Why isn't this :after element working?

I have a preloader on my page which should be displaying an animation. 我的页面上有一个预加载器,应该显示动画。 The animation should be showing on top of the dark black background before the page has loaded... but the animation is not displaying. 在页面加载之前,动画应该显示在深黑色背景上...但是动画没有显示。

http://www.samnorris.net/portfolio-ss/ http://www.samnorris.net/portfolio-ss/

The animation works if I put it's CSS into #windowloader, but because I need it to be on top of a solid background (to hide unloaded content...) I thought to put it into an :after pseudo-class to load it on top of the #windowloader div... but for some reason this is not working. 如果将CSS放入#windowloader中,动画就可以工作,但是因为我需要将其放在坚实的背景之上(以隐藏未加载的内容...),所以我想将其放入:after伪类中以将其加载到#windowloader div的顶部...,但是由于某种原因,这不起作用。

is my CSS incorrect, or something else...? 我的CSS不正确,还是其他原因?

Here is the Codepen which shows the animation that should be displaying: http://codepen.io/devilishalchemist/pen/emOVYQ 这是显示应该显示的动画的Codepen: http ://codepen.io/devilishalchemist/pen/emOVYQ

HTML: HTML:

<div id="windowloader">
    <span></span>
    <span></span>
    <span></span>
    <span></span>
</div>

Relevant CSS from my page: 我页面上的相关CSS:

/* ==========================================================================
  PAGE LOADER
========================================================================== */


.nonscroll {
  overflow: hidden;
}


#windowloader {
  overflow: auto;
  top:0;
  left: 0;
  width: 100%;
  height: 100%;
  position: fixed;
  z-index: 999998;
  display: table;
  background: $black;
}

#windowloader {

  &:after {

  content: '';
  display: block;
  position: absolute;
  z-index: 999999;
  top: 50%;
  left: 50%;
  width: 80px;
  height: 80px;
  transform: translate(-50%, -50%) rotate(45deg) translate3d(0, 0, 0);
  animation: loader 1.2s infinite ease-in-out;

  span {
    position: absolute;
    display: block;
    width: 40px;
    height: 40px;
    background-color: #EE4040;
    animation: loaderBlock 1.2s infinite ease-in-out both;

    &:nth-child(1) {
      top: 0;
      left: 0;
    }
    &:nth-child(2) {
      top: 0;
      right: 0;
      animation: loaderBlockInverse 1.2s infinite ease-in-out both;
    }
    &:nth-child(3) {
      bottom: 0;
      left: 0;
      animation: loaderBlockInverse 1.2s infinite ease-in-out both;
    }
    &:nth-child(4) {
      bottom: 0;
      right: 0;
    }
  }

  /*LOAD FINISH*/
  .loaded {
    top: -100%;
  }

 }
}

   @keyframes loader {
      0%, 10%, 100% {
        width: 80px;
        height: 80px;
      }
      65% {
        width: 150px;
        height: 150px;
      }
    }
    @keyframes loaderBlock {
      0%, 30% {
        transform: rotate(0);
      }
      55% {
        background-color: #F37272;
      }
      100% {
        transform: rotate(90deg);

      }
    }
    @keyframes loaderBlockInverse {
      0%, 20% {
        transform: rotate(0);
      }
      55% {
        background-color: #F37272;
      }
      100% {
        transform: rotate(-90deg);
      }
    }

FWIW, I have also tried: FWIW,我也尝试过:

#windowloader:after { }

Javascript: 使用Javascript:

///////////////////////////////////////////////////////////////////////////
// Window Loader
///////////////////////////////////////////////////////////////////////////


$("#windowloader").transitioncss("transitionEndOpen","loaded",{duration:2000,delay:1000});

$("#windowloader").off("transitionEndOpen").on( "transitionEndOpen", function(){
    $("body").removeClass('nonscroll');
    $("#windowloader").remove();
    $("#portfoliogrid").isotope('layout');
    $("#isotopeMembers").isotope('layout');
    $(".isotopeBlog").isotope('layout');
});

Bah,没关系-我只是将动画放在#windowloader div内的单独div中,我想这可能效果很好。

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

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