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

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


请如何实现更改甜蜜警报2的叠加背景?

最佳答案

为此,您可以仅使用jQuery选择器并选择o​​verlay元素。

<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。

祝好运。

10-05 20:54
查看更多