扩展可折叠div后阻止ui

时间:2014-12-15 07:52:41

标签: javascript jquery css twitter-bootstrap

在我的应用程序中,我正在进行ajax调用以获取一些数据。我正在显示一个微调器,并通过以下代码阻止ui:



function myFunction() {
  $(".spinner").show();
  $('#shadow').addClass('blocker');
  setTimeout(function() {
    $(".spinner").hide();
    $('#shadow').removeClass('blocker');
  }, 3000);
}

.spinner {
  position: absolute;
  right: 45%;
  bottom: 50%;
  z-index: 9999;
}
.shadow {
  z-index: 900
}
.blocker {
  z-index: 1000;
  height: 100%;
  width: 100%;
  background: #000000;
  opacity: 0.3;
  left: 0;
  top: 0;
  position: absolute;
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
<link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet" />



<button onclick="myFunction()">Try it</button>

<div id="accordion" class="panel-group">
  <div class="panel panel-default">
    <div class="panel-heading">
      <h4 class="panel-title">
                <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne">1. What is HTML?</a>
            </h4>
    </div>
    <div id="collapseOne" class="panel-collapse collapse">
      <div class="panel-body">
        <p>1Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
      </div>
    </div>
  </div>
  <div class="panel panel-default">
    <div class="panel-heading">
      <h4 class="panel-title">
                <a data-toggle="collapse" data-parent="#accordion" href="#collapseTwo">2. What is Twitter Bootstrap?</a>
            </h4>
    </div>
    <div id="collapseTwo" class="panel-collapse collapse">
      <div class="panel-body">
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
      </div>
    </div>
  </div>
  <div class="panel panel-default">
    <div class="panel-heading">
      <h4 class="panel-title">
                <a data-toggle="collapse" data-parent="#accordion" href="#collapseThree">3. What is CSS?</a>
            </h4>
    </div>
    <div id="collapseThree" class="panel-collapse collapse">
      <div class="panel-body">
        <p>3Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
      </div>
    </div>
  </div>
</div>


<div id="shadow"></div>

<div id="spinner" class="spinner" style="display: none;">Loading...</div>
&#13;
&#13;
&#13;

此代码正常工作,直到我花费一个链接。如果我在花费任何链接后按下按钮,那么黑色图层不会占据页面的全部高度。

重现的步骤: -

  • 消费任何链接
  • 点击按钮
  • 向下滚动以查看问题。

我尝试使用溢出属性但没有运气。

黑色层如何在所有情况下都达到全高(带链接消耗)?

1 个答案:

答案 0 :(得分:1)

试试这个.blocker{position: fixed;}

&#13;
&#13;
function myFunction() {
  $(".spinner").show();
  $('#shadow').addClass('blocker');
  setTimeout(function() {
    $(".spinner").hide();
    $('#shadow').removeClass('blocker');
  }, 3000);
}
&#13;
.spinner {
  position: absolute;
  right: 45%;
  bottom: 50%;
  z-index: 9999;
}
.shadow {
  z-index: 900
}
.blocker {
  z-index: 1000;
  height: 100%;
  width: 100%;
  background: #000000;
  opacity: 0.3;
  left: 0;
  top: 0;
  position: fixed;/* change absolute to fixed */
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
<link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet" />



<button onclick="myFunction()">Try it</button>

<div id="accordion" class="panel-group">
  <div class="panel panel-default">
    <div class="panel-heading">
      <h4 class="panel-title">
                <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne">1. What is HTML?</a>
            </h4>
    </div>
    <div id="collapseOne" class="panel-collapse collapse">
      <div class="panel-body">
        <p>1Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
      </div>
    </div>
  </div>
  <div class="panel panel-default">
    <div class="panel-heading">
      <h4 class="panel-title">
                <a data-toggle="collapse" data-parent="#accordion" href="#collapseTwo">2. What is Twitter Bootstrap?</a>
            </h4>
    </div>
    <div id="collapseTwo" class="panel-collapse collapse">
      <div class="panel-body">
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
      </div>
    </div>
  </div>
  <div class="panel panel-default">
    <div class="panel-heading">
      <h4 class="panel-title">
                <a data-toggle="collapse" data-parent="#accordion" href="#collapseThree">3. What is CSS?</a>
            </h4>
    </div>
    <div id="collapseThree" class="panel-collapse collapse">
      <div class="panel-body">
        <p>3Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
        <p>2Div</p>
      </div>
    </div>
  </div>
</div>


<div id="shadow"></div>

<div id="spinner" class="spinner" style="display: none;">Loading...</div>
&#13;
&#13;
&#13;