javascripttwitter-bootstrapgridbootstrap-modalpackery

Grids getting stacked inside the modal pop-up


I have 5 grids inside a bootstrap modal pop-up.

When I click on the popup button,the grids are stacked one over the other.When I drag one grid,whole 5 grids are getting accumulated properly.Once this is done.It is working fine from next clicks of popup button.

Code follows

<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>

<!-- Modal -->
<div id="myModal" class="modal fade" role="dialog">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Modal Header</h4>
      </div>
      <div class="modal-body">
        <h1>Image sort</h1>
<div class="packery">
  <div class="item w2 h2 i1" tabindex="0">A</div>
  <div class="item w2 h2 i2" tabindex="1">B</div>
  <div class="item w2 h2 i3" tabindex="2">C</div>
  <div class="item w2 h2 i4" tabindex="3">D</div>
  <div class="item w2 h2 i5" tabindex="4">E</div>
</div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>

Fiddle Demo here


Solution

  • Just put code inside bootstrap modal event listener, so it initialize after modal shown

    $(document).ready(function(){
        $('#myModal').on('shown.bs.modal', function () {
            // grid code
         });
    });
    

    Fiddle