如何在打开子模态时模糊主模态?

时间:2017-07-06 12:37:04

标签: jquery css twitter-bootstrap

我想像这样模糊主模态(google plus的模态快照):

1

我正在关注并实现这一目标:

2

我正在使用bootstrap模式(最新版本)来工作。但the doc没有提及子模态。所以,我的问题是:我该怎么做?

以下是基于我尝试过的示例:

    (function (global) {
        $(document).ready(function () {
        
            // using this function to center subModal (width/height)
        
            let addLinkModalOnShow = function () {
                let c = $(this).find('.modal-content'),
                    h1 = $(global).height(),
                    h2 = c.height(),
                    w1 = $('#myModal .modal-content').width(),
                    w2 = c.width();
                
                c.css({ 'margin-top': h1 / 2 - (h2 / 2), 'margin-left': w1 / 2 - (w2 / 2) });
            };

            $(document).on('shown.bs.modal', '.modal#subModal', addLinkModalOnShow);
        });
    }(window));
#subModal .modal-content {
  width: 300px;
  height: 170px;
}
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>



<!-- Button trigger modal -->
<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
  Launch demo modal
</button>

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">Main modal</h4>
      </div>
      <div class="modal-body">
        ...
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#subModal">Open sub modal</button>
      </div>
    </div>
  </div>
</div>

<!-- Modal -->
<div class="modal fade" id="subModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">Sub modal</h4>
      </div>
      <div class="modal-body">
        ...
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>

谢谢!

0 个答案:

没有答案