bootstrap 4模态背景样式(特定模态)

dem*_*der 5 css jquery modal-dialog twitter-bootstrap 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');
            })
Run Code Online (Sandbox Code Playgroud)

codepen:https://codepen.io/rae0724/pen/oqmPmY

Zim*_*Zim 6

You can add a custom class to the body before the modal is opened, and then remove the class when it's closed...

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

The you just need the CSS for the custom color applied to the backdrop.

.example-open .modal-backdrop {background-color:red;}
Run Code Online (Sandbox Code Playgroud)

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