bootstrap: change modal backdrop opacity only for specific modals(bootstrap:仅针对特定模态更改模态背景不透明度)
问题描述
我有一个包含多个模式的菜单.当我打开一个在另一个上时,它会将背景变成黑色,这很难看.我知道我需要更改 filter: alpha(opacity=80);
in .modal-backdrop.fade.in
in bootstrap.css.但我需要更改它不是针对所有模态,仅针对其中一些模态.这是第一个模态的html代码
I have a menu with multiple modals. When I open one over another it turns backgrount into black, which is ugly.
I understand that I need change filter: alpha(opacity=80);
in .modal-backdrop.fade.in
in bootstrap.css. But I need to change it not for all modals, only for some of them. Here's the html code for first modal
<div class="modal hide" id="mbusModal">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h3>MBUS</h3>
</div>
<div class="modal-body">
<form class="form-horizontal">
<form class="well form-inline">
<input type="button" class="btn" onclick="$('#dinMbusModal').modal('show'); $('#tabsMbusDin a:last').tab('show');" value="din">
</form>
</div>
<div class="modal-footer">
<a href="#" class="btn" data-dismiss="modal">Закрыть</a>
<a href="#" class="btn btn-primary" onclick="addPort('mbus',$('#mbusDev').val(),$('#mbusSpeed').val()); $('#mbusModal').modal('hide')">Применить</a>
</div>
这个模态需要改变他的背景:
This modal needs to change his backdrop:
<div class="modal hide" id="dinMbusModal" style="width: 500px; margin: -250px 0 0 -250px;">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h3>DIN</h3>
</div>
<div class="modal-body">
</div>
<div class="modal-footer">
<a href="#" class="btn" data-dismiss="modal">Закрыть</a>
<a href="#" class="btn btn-primary" onclick="addPort('din_mbus',,); $('#dinMbusModal').modal('hide')">Применить</a>
</div>
</div>
推荐答案
背景是由 Modal 插件动态生成的,这有点复杂.一种可能的方法是在收到 show 事件时向 body 添加一个类,然后在 hidden 上将其删除.
Little bit complicated by the fact that the backdrop is generated by the Modal plugin on the fly. One possible way of doing it is adding a class to the body when you get a show event, then remove it on the hidden.
类似:
.modal-color-red .modal-backdrop {
background-color: #f00;
}
.modal-color-green .modal-backdrop {
background-color: #0f0;
}
.modal-color-blue .modal-backdrop {
background-color: #00f;
}
JS
$('.modal[data-color]').on('show hidden', function () {
$('body').toggleClass('modal-color-'+ $(this).data('color'));
});
HTML
<div class="modal hide fade" id="redModal" data-color="red">...</div>
<div class="modal hide fade" id="greenModal" data-color="green">...</div>
<div class="modal hide fade" id="blueModal" data-color="blue">...</div>
这篇关于bootstrap:仅针对特定模态更改模态背景不透明度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:bootstrap:仅针对特定模态更改模态背景不透明度


基础教程推荐
- Karma-Jasmine:如何正确监视 Modal? 2022-01-01
- 我什么时候应该在导入时使用方括号 2022-01-01
- 在 JS 中获取客户端时区(不是 GMT 偏移量) 2022-01-01
- 动态更新多个选择框 2022-01-01
- 有没有办法使用OpenLayers更改OpenStreetMap中某些要素 2022-09-06
- 角度Apollo设置WatchQuery结果为可用变量 2022-01-01
- 当用户滚动离开时如何暂停 youtube 嵌入 2022-01-01
- 响应更改 div 大小保持纵横比 2022-01-01
- 在for循环中使用setTimeout 2022-01-01
- 悬停时滑动输入并停留几秒钟 2022-01-01