I wondered how can I change the colour of the modal backdrop (not the background colour of modal) for specific modal.
The colour can be changed if I use "shown.bs.modal" with some delays. But I want to change the backdrop colour immediately. Hope somebody can help. Thank you.
<!-- 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">×</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');
})
codepen: https://codepen.io/rae0724/pen/oqmPmY
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");
})
The you just need the CSS for the custom color applied to the backdrop.
.example-open .modal-backdrop {background-color:red;}
https://www.codeply.com/go/oNKsVikW6n
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With