3

我最近将甜蜜警报 1 移到了甜蜜警报 2,但根据文档,没有选项可以为像甜蜜警报 1 这样的警报框的覆盖背景设置主题

.swal-overlay {
  background-color: rgba(43, 165, 137, 0.45);
}.

请问我怎样才能实现改变甜蜜警报2的覆盖背景?

4

3 回答 3

3
Swal.fire({
  icon: 'success',
  background: 'red',
})
于 2021-02-06T13:23:28.383 回答
2

要实现这一点,您可以使用 jQuery 选择器并像这样选择覆盖元素。

<button type="button" onclick="opentheSwal();">OK</button>
<script>
    function opentheSwal() {
        swal(
            'Good job!',
            'You clicked the button!',
            'success'
        );
        $(".swal2-modal").css('background-color', '#000');//Optional changes the color of the sweetalert 
        $(".swal2-container.in").css('background-color', 'rgba(43, 165, 137, 0.45)');//changes the color of the overlay
    }
</script>

您必须选择.swal2-container.in更改覆盖并使用 jqueries.css()函数应用 css。

祝你好运。

于 2017-10-29T23:58:36.653 回答
0

我遇到了同样的问题,发现有必要添加!important到 CSS 中:

.swal2-container.swal2-backdrop-show, .swal2-container.swal2-noanimation {
    background: rgba(0,0,0,.95)!important;
}
于 2021-10-04T06:57:08.220 回答