我已经直接从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;
}

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


当前回答

我发现:

在bootstrap 3.3.0中这是不正确的,但在bootstrap 3.3.5中这是正确的。让我们看看代码。 3.3.0:

this.$backdrop = $('<div class="modal-backdrop ' + animate + '" />')
    .prependTo(this.$element)

3.3.5

  this.$backdrop = $(document.createElement('div'))
        .addClass('modal-backdrop ' + animate)
        .appendTo(this.$body)

其他回答

我有一个更轻更好的解决方案。

它可以很容易地解决通过一些额外的CSS样式..

隐藏类.modal- background(从Bootstrap.js自动生成) .modal-backdrop { 显示:没有; 可见性:隐藏; 位置:相对 } 将.modal的背景设置为半透明的黑色背景图像。 .modal { 背景:url(“http://bin.smwcentral.net/u/11361/BlackTransparentBackground.png”) //来自谷歌图像的半透明图像 z - index: 1100; }

如果你有一个需求,需要模态在元素内部,而不是在</body>标签附近,这将是最好的工作。

我也有同样的问题,也检查了Muhd的答案。

但是,我的模态需要左,顶部属性,所以只要把固定位置改为绝对,它就工作了。

.modal {
    position: absolute;
}

我只在iOS设备上遇到过类似的问题。

解决方案是从父元素中删除-webkit-overflow-scrolling: touch

我发现通过添加内联样式标签来设置“display: none”可以防止这个问题。代码的位置没有任何影响。

角:

($('.modal-backdrop') as any).remove();