使用jQuery的CSS特定Div重叠

时间:2015-05-19 08:01:19

标签: css ajax css3 overlay loading

Heyya,

我在一个应用程序中有一个仪表板,其中包含相当多的div,并且每个div的内部html都是通过远程ajax调用设置的。我需要做的是将加载动画(带有微调器等的叠加加载)放到每个div 中,一旦完成ajax回调,我将删除那些加载叠加...

到目前为止,我已经达到了这一点,但是我无法在特定的div中找到它,这个加载遍布整个页面,无论我在哪里加载div :(任何想法?

<div class="profile-sidebar" style="width: 250px;" id="divUserProfileInfo">
            <div class="loading">Loading&#8230;</div> etc etc etc </div></div>

css:

&#13;
&#13;
.loading {

  position: fixed;

  z-index: 999;

  height: 2em;

  width: 2em;

  overflow: show;

  margin: auto;

  top: 0;

  left: 0;

  bottom: 0;

  right: 0;

}

/* Transparent Overlay */

.loading:before {

  content: '';

  display: block;

  position: fixed;

  top: 0;

  left: 0;

  width: 100%;

  height: 100%;

  background-color: rgba(0, 0, 0, 0.3);

}

/* :not(:required) hides these rules from IE9 and below */

.loading:not(:required) {

  /* hide "loading..." text */

  font: 0/0 a;

  color: transparent;

  text-shadow: none;

  background-color: transparent;

  border: 0;

}

.loading:not(:required):after {

  content: '';

  display: block;

  font-size: 10px;

  width: 1em;

  height: 1em;

  margin-top: -0.5em;

  -webkit-animation: spinner 1500ms infinite linear;

  -moz-animation: spinner 1500ms infinite linear;

  -ms-animation: spinner 1500ms infinite linear;

  -o-animation: spinner 1500ms infinite linear;

  animation: spinner 1500ms infinite linear;

  border-radius: 0.5em;

  -webkit-box-shadow: rgba(0, 0, 0, 0.75) 1.5em 0 0 0, rgba(0, 0, 0, 0.75) 1.1em 1.1em 0 0, rgba(0, 0, 0, 0.75) 0 1.5em 0 0, rgba(0, 0, 0, 0.75) -1.1em 1.1em 0 0, rgba(0, 0, 0, 0.5) -1.5em 0 0 0, rgba(0, 0, 0, 0.5) -1.1em -1.1em 0 0, rgba(0, 0, 0, 0.75) 0 -1.5em 0 0, rgba(0, 0, 0, 0.75) 1.1em -1.1em 0 0;

  box-shadow: rgba(0, 0, 0, 0.75) 1.5em 0 0 0, rgba(0, 0, 0, 0.75) 1.1em 1.1em 0 0, rgba(0, 0, 0, 0.75) 0 1.5em 0 0, rgba(0, 0, 0, 0.75) -1.1em 1.1em 0 0, rgba(0, 0, 0, 0.75) -1.5em 0 0 0, rgba(0, 0, 0, 0.75) -1.1em -1.1em 0 0, rgba(0, 0, 0, 0.75) 0 -1.5em 0 0, rgba(0, 0, 0, 0.75) 1.1em -1.1em 0 0;

}

/* Animation */

@-webkit-keyframes spinner {

  0% {

    -webkit-transform: rotate(0deg);

    -moz-transform: rotate(0deg);

    -ms-transform: rotate(0deg);

    -o-transform: rotate(0deg);

    transform: rotate(0deg);

  }

  100% {

    -webkit-transform: rotate(360deg);

    -moz-transform: rotate(360deg);

    -ms-transform: rotate(360deg);

    -o-transform: rotate(360deg);

    transform: rotate(360deg);

  }

}

@-moz-keyframes spinner {

  0% {

    -webkit-transform: rotate(0deg);

    -moz-transform: rotate(0deg);

    -ms-transform: rotate(0deg);

    -o-transform: rotate(0deg);

    transform: rotate(0deg);

  }

  100% {

    -webkit-transform: rotate(360deg);

    -moz-transform: rotate(360deg);

    -ms-transform: rotate(360deg);

    -o-transform: rotate(360deg);

    transform: rotate(360deg);

  }

}

@-o-keyframes spinner {

  0% {

    -webkit-transform: rotate(0deg);

    -moz-transform: rotate(0deg);

    -ms-transform: rotate(0deg);

    -o-transform: rotate(0deg);

    transform: rotate(0deg);

  }

  100% {

    -webkit-transform: rotate(360deg);

    -moz-transform: rotate(360deg);

    -ms-transform: rotate(360deg);

    -o-transform: rotate(360deg);

    transform: rotate(360deg);

  }

}

@keyframes spinner {

  0% {

    -webkit-transform: rotate(0deg);

    -moz-transform: rotate(0deg);

    -ms-transform: rotate(0deg);

    -o-transform: rotate(0deg);

    transform: rotate(0deg);

  }

  100% {

    -webkit-transform: rotate(360deg);

    -moz-transform: rotate(360deg);

    -ms-transform: rotate(360deg);

    -o-transform: rotate(360deg);

    transform: rotate(360deg);

  }

}
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

.loading div有一个固定的位置,无论其父div的位置如何,都会定位。要使.loading div仅显示在特定div中,请将.loading的位置更改为绝对,将父级div更改为 relative