居中的模态负载微调器引导程序 4
Posted
技术标签:
【中文标题】居中的模态负载微调器引导程序 4【英文标题】:Centered modal load spinner bootstrap 4 【发布时间】:2018-06-22 01:28:20 【问题描述】:我想要一个模态负载微调器,并基于 Bootstrap 4 的模态对话框进行了测试。但是,我无法让模式在页面上水平居中。如果可能的话,我还希望模态框没有边框且透明(因此看起来只有微调器悬停在页面上)
function modal()
$('.modal').modal('show');
setTimeout(function ()
console.log('hejsan');
$('.modal').modal('hide');
, 3000);
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/css/bootstrap.min.css" integrity="sha384-Zug+QiDoJOrZ5t4lssLdxGhVrurbmBWopoEl+M6BdEfwnCJZtKxi1KgxUyJq13dy" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/js/bootstrap.min.js" integrity="sha384-a5N7Y/aK3qNeh15eJKGWxsqtnX/wWdSZSKp+81YjTmS15nvnvxKHuzaWwXHDli+4" crossorigin="anonymous"></script>
<button type="button" class="btn btn-primary" onclick="modal();">Open and close in 3 secs</button>
<div class="modal fade bd-example-modal-lg" data-backdrop="static" data-keyboard="false" tabindex="-1">
<div class="modal-dialog modal-sm">
<div class="modal-content" style="width: 48px">
<span class="fa fa-spinner fa-spin fa-3x"></span>
</div>
</div>
</div>
<p>I would like the <ul><li>spinner horizontally centered on page<li> the modal transparent without borders</ul></p>
【问题讨论】:
【参考方案1】:应用这两个类:
.bd-example-modal-lg .modal-dialog
display: table;
position: relative;
margin: 0 auto;
top: calc(50% - 24px);
.bd-example-modal-lg .modal-dialog .modal-content
background-color: transparent;
border: none;
function modal()
$('.modal').modal('show');
setTimeout(function ()
console.log('hejsan');
$('.modal').modal('hide');
, 3000);
.bd-example-modal-lg .modal-dialog
display: table;
position: relative;
margin: 0 auto;
top: calc(50% - 24px);
.bd-example-modal-lg .modal-dialog .modal-content
background-color: transparent;
border: none;
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/css/bootstrap.min.css" integrity="sha384-Zug+QiDoJOrZ5t4lssLdxGhVrurbmBWopoEl+M6BdEfwnCJZtKxi1KgxUyJq13dy" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/js/bootstrap.min.js" integrity="sha384-a5N7Y/aK3qNeh15eJKGWxsqtnX/wWdSZSKp+81YjTmS15nvnvxKHuzaWwXHDli+4" crossorigin="anonymous"></script>
<button type="button" class="btn btn-primary" onclick="modal();">Open and close in 3 secs</button>
<div class="modal fade bd-example-modal-lg" data-backdrop="static" data-keyboard="false" tabindex="-1">
<div class="modal-dialog modal-sm">
<div class="modal-content" style="width: 48px">
<span class="fa fa-spinner fa-spin fa-3x"></span>
</div>
</div>
</div>
<p>I would like the <ul><li>spinner horizontally centered on page<li> the modal transparent without borders</ul></p>
【讨论】:
太好了,谢谢。我已经用你的 css 更新了 jsbin,并将微调器放在页面高度的 1/3 处。对我来说看起来好一点。 jsbin.com/cezejuk/edit?html,output 对我来说,02 自定义使其在 Chrome 上完美 1) 删除 modal-content 宽度,2) fa-spinner 的字体大小为 6rem【参考方案2】:旧帖子,我知道,但这对我来说似乎是一个更清洁的选择...
function modal()
$('.modal').modal('show');
setTimeout(function ()
console.log('hejsan');
$('.modal').modal('hide');
, 3000);
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/css/bootstrap.min.css" integrity="sha384-Zug+QiDoJOrZ5t4lssLdxGhVrurbmBWopoEl+M6BdEfwnCJZtKxi1KgxUyJq13dy" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/js/bootstrap.min.js" integrity="sha384-a5N7Y/aK3qNeh15eJKGWxsqtnX/wWdSZSKp+81YjTmS15nvnvxKHuzaWwXHDli+4" crossorigin="anonymous"></script>
<button type="button" class="btn btn-primary" onclick="modal();">Open and close in 3 secs</button>
<div class="modal fade" tabindex="-1" role="dialog" id="spinnerModal">
<div class="modal-dialog modal-dialog-centered text-center" role="document">
<span class="fa fa-spinner fa-spin fa-3x w-100"></span>
</div>
</div>
<p>I would like the <ul><li>spinner horizontally centered on page<li> the modal transparent without borders</ul></p>
【讨论】:
【参考方案3】:使用d-flex
和justify-content-center
类的Bootstrap 4.x。
<div class="modal fade" id="loadingModal" tabindex="-1" role="dialog">
<div class="modal-dialog modal-dialog-centered d-flex justify-content-center" role="document">
<div class="spinner-border" role="status">
<span class="sr-only">Loading...</span>
</div>
</div>
</div>
【讨论】:
【参考方案4】:您可以再删除一个类。因为modal-dialog
是一个弹性盒子。
text-center
+ w-100
-> justify-content-center
function modal()
$('.modal').modal('show');
setTimeout(function ()
console.log('completed');
$('.modal').modal('hide');
, 3000);
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/css/bootstrap.min.css" integrity="sha384-Zug+QiDoJOrZ5t4lssLdxGhVrurbmBWopoEl+M6BdEfwnCJZtKxi1KgxUyJq13dy" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/js/bootstrap.min.js" integrity="sha384-a5N7Y/aK3qNeh15eJKGWxsqtnX/wWdSZSKp+81YjTmS15nvnvxKHuzaWwXHDli+4" crossorigin="anonymous"></script>
<button type="button" class="btn btn-primary" onclick="modal();">Open and close in 3 secs</button>
<div class="modal fade" tabindex="-1" role="dialog">
<div class="modal-dialog modal-dialog-centered justify-content-center" role="document">
<span class="fa fa-spinner fa-spin fa-3x"></span>
</div>
</div>
<p>I would like the <ul><li>spinner horizontally centered on page<li> the modal transparent without borders</ul></p>
【讨论】:
以上是关于居中的模态负载微调器引导程序 4的主要内容,如果未能解决你的问题,请参考以下文章