Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap 4 Modal Slide from Left

I need the bootstrap modal to be open by slide from Left. However, the function can only work on Bootstrap 3 but not Bootstrap 4.

Bootstrap 3 ver. : https://codepen.io/bootpen/pen/jbbaRa , Bootstrap 4 ver. : https://codepen.io/rae0724/pen/yKZjax

<div class="modal left fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        ...
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>

.modal.left .modal-dialog {
    position: fixed;
    margin: auto;
    width: 320px;
    height: 100%;
    -webkit-transform: translate3d(0%, 0, 0);
    -ms-transform: translate3d(0%, 0, 0);
    -o-transform: translate3d(0%, 0, 0);
    transform: translate3d(0%, 0, 0);
}

.modal.left .modal-content {
    height: 100%;
    overflow-y: auto;
}

.modal.left .modal-body {
    padding: 15px 15px 80px;
}

.modal.left.fade .modal-dialog {
    left: -320px;
    -webkit-transition: opacity 0.3s linear, left 0.3s ease-out;
    -moz-transition: opacity 0.3s linear, left 0.3s ease-out;
    -o-transition: opacity 0.3s linear, left 0.3s ease-out;
    transition: opacity 0.3s linear, left 0.3s ease-out;
}

.modal.left.fade.in .modal-dialog {
    left: 0;
}
like image 319
demoncoder Avatar asked Apr 10 '18 11:04

demoncoder


1 Answers

In Bootstrap 4, .in has changed to .show. The custom CSS should be:

.modal.left.fade.show .modal-dialog {
    left: 0;
}

Also, the Codepen was broken because the latest Bootstrap 4 and popper.js wasn't included.

Working demo on Codeply

like image 159
Zim Avatar answered Nov 04 '22 01:11

Zim