Magnific-Popup with Bootstrap Modal Image Display Problem

Asked

Viewed 962 times

4

I am facing the problem of displaying image inside the modal bootstrap.

Use this plugin : Magnific-Popup

Follows the code:

HTML:

<!-- Button trigger modal -->
<button type="button" id="mymodal" 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">Modal title</h4>
      </div>
      <div class="modal-body">
        <a class="test-popup-link" href="http://i.imgur.com/YZ7AGyF.jpg">Open popup</a>
      </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>

JS:

$(document).ready(function() {
  $('.test-popup-link').magnificPopup({
    type: 'image'
  });
});

Final result:

inserir a descrição da imagem aqui

Here is jsfiddle: http://jsfiddle.net/1aeur58f/106/

NOTE: The image should not be behind the modal, always ahead of the modal.

Some brilliant solution ?

1 answer

3


You have to create a body div.mfp-wrap { z-index: 999999 !important; } so that the element is on the modal.

$(document).ready(function() {
  $('.test-popup-link')
    .magnificPopup({
      type: 'image'
    });
});
body div.mfp-wrap { z-index: 999999 !important; }
.modal {
  text-align: center;
  padding: 0!important;
}

.modal:before {
  content: '';
  display: inline-block;
  height: 100%;
  vertical-align: middle;
  margin-right: -4px;
}

.modal-dialog {
  display: inline-block;
  text-align: left;
  vertical-align: middle;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<link href="https://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/magnific-popup.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/jquery.magnific-popup.js"></script>


<!-- Button trigger modal -->
<button type="button" id="mymodal" 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">Modal title</h4>
      </div>
      <div class="modal-body">
        <a class="test-popup-link" href="http://i.imgur.com/YZ7AGyF.jpg">Open popup</a>
      </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>

  • Virgilio Novic, gives a help, when opening a small image, the modal does not turn black. See this example : http://jsfiddle.net/1aeur58f/109/

  • 1

    @Matheusmiranda I added three more css, but, what it will do to centralize the modal so that the image stays totally on it, of course the image has to be larger than the modal rssrs

  • 1

    @Matheusmiranda not only use this css that posted have to center so that he stay behind even I just tested

  • Virgilio Novic gets this: http://jsfiddle.net/1aeur58f/113/

  • 1

    I saw @Matheusmiranda.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.