Html 如何在 bootstrap 3 模式中将 spin.js 微调器居中?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18795967/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to center spin.js spinner in bootstrap 3 modal?
提问by fat fantasma
I am trying to display and center the spin.js spinner in a Bootstrap 3 modal. Using the code below I got it to work in IE and FF but NOT in Chrome, Safari Desktop, Chrome IOS, Safari IOS.
我正在尝试在 Bootstrap 3 模式中显示 spin.js 微调器并使其居中。使用下面的代码,我让它在 IE 和 FF 中工作,但不能在 Chrome、Safari 桌面、Chrome IOS、Safari IOS 中工作。
The problem seems to be tied to the fade in animation (gray backdrop overlay) because when I set the modal class to just "modal show" it works but with no fade in animation of course. See this jsfiddle. It's when I use "$('#Searching_Modal").modal('show');" that it does not work in some of the browsers described above.
问题似乎与动画淡入(灰色背景叠加)有关,因为当我将模态类设置为“模态显示”时,它可以工作,但当然没有动画淡入。看到这个jsfiddle。当我使用 "$('#Searching_Modal").modal('show');" 时,它在上述某些浏览器中不起作用。
Run this jsfiddleon both chrome and firefox and you will see what I mean. Does anybody know how to fix this or do it properly? I do want the bootstrap modal fade in to work.
在 chrome 和 firefox 上运行这个jsfiddle,你就会明白我的意思。有谁知道如何解决这个问题或正确地做到这一点?我确实希望引导模式淡入工作。
I'm using Bootstrap 3 and spin.js.
我正在使用 Bootstrap 3 和 spin.js。
<div id="Searching_Modal" class="modal fade" tabindex="-1" role="dialog" data-keyboard="false"
data-backdrop="static">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header" style="text-align: center">
<h3>Searching for Seats</h3>
</div>
<div class="modal-body">
<br>
<br>
<br>
<div id="searching_spinner_center" style="position:fixed; left:50%"></div>
<br>
<br>
<br>
</div>
<div class="modal-footer" style="text-align: center"></div>
</div>
</div>
Here is the spin.js set up code:
这是 spin.js 设置代码:
var opts = {
lines: 13, // The number of lines to draw
length: 20, // The length of each line
width: 10, // The line thickness
radius: 30, // The radius of the inner circle
corners: 1, // Corner roundness (0..1)
rotate: 0, // The rotation offset
direction: 1, // 1: clockwise, -1: counterclockwise
color: '#000', // #rgb or #rrggbb or array of colors
speed: 1, // Rounds per second
trail: 60, // Afterglow percentage
shadow: false, // Whether to render a shadow
hwaccel: false, // Whether to use hardware acceleration
className: 'spinner', // The CSS class to assign to the spinner
zIndex: 2e9, // The z-index (defaults to 2000000000)
top: 'auto', // Top position relative to parent in px
left:'auto' // Left position relative to parent in px
};
//var target = document.getElementById('center_spinner');
var target = document.getElementById('searching_spinner_center');
var spinner = new Spinner(opts).spin(target);
回答by userfb
Try replacing div.modal-body by
尝试将 div.modal-body 替换为
<div class="modal-body" >
<div style="height:200px">
<span id="searching_spinner_center" style="position: absolute;display: block;top: 50%;left: 50%;"></span>
</div>
</div>
Work for me. http://jsfiddle.net/D6rD6/5/