jquery - bootstrap 4 modal-backdrop样式(特定modal)

标签 jquery css twitter-bootstrap modal-dialog bootstrap-4

我想知道如何更改特定模态的模态背景颜色(不是模态的背景颜色)。

如果我使用“shown.bs.modal”并有一些延迟,则可以更改颜色。但我想立即更改背景颜色。 希望有人能帮忙。谢谢。

<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        ...
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>

$('#exampleModal').on('show.bs.modal', function (e) {
                $(".modal-backdrop").css('background', '#fb0404');
            })

代码笔:https://codepen.io/rae0724/pen/oqmPmY

最佳答案

您可以在模态框打开之前向主体添加自定义类,然后在模态框关闭时删除该类...

$('#exampleModal').on('show.bs.modal', function (e) {
    $('body').addClass("example-open");
}).on('hide.bs.modal', function (e) {
    $('body').removeClass("example-open");
})

您只需要 CSS 将自定义颜色应用于背景。

.example-open .modal-backdrop {background-color:red;}

https://www.codeply.com/go/oNKsVikW6n

关于jquery - bootstrap 4 modal-backdrop样式(特定modal),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49755130/

相关文章:

javascript - jQuery 返回错误的文档高度

javascript - 带有内联 block 的无限滚动幻灯片?

jquery - 如何计算隐藏 div 内可见集元素的数量?

c# - 使用 JQuery 重新加载部分 View

css - 转换 SVG 元素(rotateX)的正确方法是什么?

android - bootstrap css 源或本地 android glyphicon 区别

html - Bootstrap 3 : Changing Jumbotron height causes background image not to be centred on resizing

javascript - 如何使用 jquery 获取元素的边框宽度?

javascript - 当我调整窗口大小时,如何更改导航栏上 li 标签的值/内容?

css - 如何解决错误 'The name of the class AccordionGroup should end with the suffix Component'