【问题标题】:Specific modal-backdrop customizing特定的模态背景定制
【发布时间】:2019-05-01 18:19:07
【问题描述】:

我可以通过将特定模式的 id 设置为选择器来更改页面中许多模式之一的 CSS。

例如 而是:

.modal {
    top: 0px;
    margin-top: 240px;
    ...
}

设置

#my_modal {
    top: 0px;
    margin-top: 240px;
    ...
}

我的问题:

如何仅更改 #my_modal 对应的 modal-backdrop 的 css?

 $('.modal').addClass('my_personal_stuff');

工作,而

 $('.modal-backdrop').addClass('my_personal_stuff');

没有用

为什么会这样?

【问题讨论】:

    标签: css twitter-bootstrap modal-dialog


    【解决方案1】:

    如何仅更改#my_modal 对应的css 模态背景?

    // Add an extra class to the modal backdrop to make it customizable
    $('.modal--custom').on('show.bs.modal', function (e) {
        setTimeout(function(){
            $('.modal-backdrop').addClass('modal-backdrop--custom');
        });
    }); 
    

    这对我有用。看看这个jsFiddle

    【讨论】:

      【解决方案2】:

      你需要绑定你的 modal 的 show 和 hide eventto,并在 .modal-backdrop div 中添加一个类。

      Jsfiddle here.

      Javascript

      function haveBackdrop() {
          if ($('.modal-backdrop').length > 0) {
              $('.modal-backdrop').addClass('my-modal-backdrop');
              clearTimeout(mBackdrop);
              return true;
          }
          return false;
      }
      var mBackdrop;
      
      $('#myModal').on('show', function() {
          mBackdrop = setTimeout("haveBackdrop()", 100);
      });
      

      CSS

      .my-modal-backdrop { /* your css backdrop modifications */ }
      

      【讨论】:

      • 它不起作用。适用于其他元素 - 例如$('.modal').addClass('my_modal_backdrop'); 但是当我尝试 $('.modal-backdrop').addClass('my_modal_backdrop'); 时没有任何反应?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-29
      • 1970-01-01
      相关资源
      最近更新 更多