gpt4 book ai didi

javascript - 展开可折叠的 div 后阻止 ui

转载 作者:太空宇宙 更新时间:2023-11-04 12:33:16 25 4
gpt4 key购买 nike

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

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>

这段代码在我扩展一个链接之前工作正常。如果我在展开任何链接后点击按钮,那么黑色图层不会占据页面的整个高度。

重现步骤:-

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

我尝试过用户溢出属性,但没有成功。

黑色层如何在所有情况下都占据全高(链接展开)?

最佳答案

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

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: fixed;/* change absolute to fixed */
}
<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>

关于javascript - 展开可折叠的 div 后阻止 ui,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27479538/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com