我已经直接从Bootstrap示例中使用了我的模态代码,并且只包括Bootstrap .js(而不是Bootstrap -modal.js)。但是,我的模态出现在灰色渐隐(背景)下面,是不可编辑的。

这是它的样子:

这是重现这个问题的一种方法。该代码的基本结构是这样的:

<body>
    <p>Lorem ipsum dolor sit amet.</p>    

    <div class="my-module">
        This container contains the modal code.
        <div class="modal fade">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-body">Modal</div>
                </div>
            </div>
        </div>
    </div>
</body>
body {
    padding-top: 50px;
}

.my-module {
    position: fixed;
    top: 0;
    left: 0;
}

你知道为什么会这样吗或者我能做些什么来弥补吗?


当前回答

你可以做一个变通,但这将从所有页面删除淡出。模态会像Facebook弹出窗口一样弹出。 打开模态尝试后:

 $('.modal-backdrop').removeClass('modal-backdrop');

其他回答

但是迟了,这里有一个通用的解决方案

    var checkeventcount = 1,prevTarget;
    $('.modal').on('show.bs.modal', function (e) {
        if(typeof prevTarget == 'undefined' || (checkeventcount==1 && e.target!=prevTarget))
        {  
          prevTarget = e.target;
          checkeventcount++;
          e.preventDefault();
          $(e.target).appendTo('body').modal('show');
        }
        else if(e.target==prevTarget && checkeventcount==2)
        {
          checkeventcount--;
        }
     });

访问这个链接-当使用固定的侧边栏时,引导3模式在背景下消失。

.modal-backdrop {
/* bug fix - no overlay */    
display: none;}

我也遇到过这个问题,没有一个解决方案对我有效,直到我发现我实际上不需要背景。您可以使用以下代码轻松删除背景。

<div class="modal fade" id="createModal" data-backdrop="false">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h4>Create Project</h4>
            </div>
            <div class="modal-body">Not yet made</div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>

注意:data- background属性需要设置为false(其他选项:static或true)。

将绝对位置更改为相对位置。

.modal-backdrop {
    position: relative;
    /* ... */
}

这个问题与父容器的定位有关。你可以很容易地将你的模式从这些容器中“移动”出来,然后再显示出来。下面是如何做到这一点,如果你显示你的模式使用js:

$('#myModal').appendTo("body").modal('show');

或者,如果你使用按钮启动模式,删除.modal('show');只要这样做:

$('#myModal').appendTo("body") 

这将保持所有正常的功能,允许您使用按钮显示模式。