如何激活Bootstrap模态背景?

时间:2013-05-10 16:43:03

标签: jquery twitter-bootstrap

我想在屏幕上放置一个叠加层,同时运行一些ajax。构建我自己的overlay div并不是什么大问题,但是,因为我已经在使用Bootstrap,我想我也可以使用它的.modal-backdrop - 它应该已经存在了,并且对于一致性有一定的价值这一切。

问题是我无法找到正确的方法 - 我尝试将类添加到.modal-backdrop,或者在其上调用.show(),但它无效。

请注意,我不想调出整个模态对话框,只是显示然后隐藏背景。

有什么建议吗?

2 个答案:

答案 0 :(得分:52)

只需将div与该类附加到body,然后在完成后将其删除:

// Show the backdrop
$('<div class="modal-backdrop"></div>').appendTo(document.body);

// Remove it (later)
$(".modal-backdrop").remove();

直播示例:

$("input").click(function() {
  var bd = $('<div class="modal-backdrop"></div>');
  bd.appendTo(document.body);
  setTimeout(function() {
    bd.remove();
  }, 2000);
});
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet" type="text/css" />
<script src="//code.jquery.com/jquery.min.js"></script>
<script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
<p>Click the button to get the backdrop for two seconds.</p>
<input type="button" value="Click Me">

答案 1 :(得分:-5)

非常奇怪,它应该开箱即用,因为“.modal-backdrop”类在css中定义为顶级。

<div class="modal-backdrop"></div>

制作了一个小型演示:http://jsfiddle.net/PfBnq/

相关问题