bootstrap 4 模态背景样式(特定模态) [英] bootstrap 4 modal-backdrop style (specific modal)

查看:23
本文介绍了bootstrap 4 模态背景样式(特定模态)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

<div class="modalfade" 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">模态标题</h5><button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>

<div class="modal-body">...

<div class="modal-footer"><button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button><button type="button" class="btn btn-primary">保存更改</button>

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

codepen: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

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">&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');
            })

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

这篇关于bootstrap 4 模态背景样式(特定模态)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
前端开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆