bootstrap 4 modal-backdrop style (specific modal)(bootstrap 4 modal-backdrop 风格(特定模态))
问题描述
我想知道如何更改特定模态的模态背景颜色(不是模态背景颜色).
I wondered how can I change the colour of the modal backdrop (not the background colour of modal) for specific modal.
如果我使用shown.bs.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
推荐答案
您可以在模态框打开之前在body中添加一个自定义类,然后在它关闭时移除该类...
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");
})
您只需要应用到背景的自定义颜色的 CSS.
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
这篇关于bootstrap 4 modal-backdrop 风格(特定模态)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:bootstrap 4 modal-backdrop 风格(特定模态)
基础教程推荐
- 直接将值设置为滑块 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01