在Bootstrap 4中从底部向上滑动的模态

时间:2019-05-11 11:58:04

标签: css twitter-bootstrap css3 bootstrap-4 css-transforms

我正在尝试设置从下向上滑动的模式,但是没有适用于Bootstrap 4的实际教程。这是一个尝试:

JSFiddle DEMO

HTML

<button type="submit" class="btn btn-block btn-default footer__btn" data-toggle="modal" data-target="#myModal2"> Open Modal</button>
<div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-body">
        Body of the modal.
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>

CSS

.modal.fade .modal-dialog {
    -webkit-transform: translate(0,100%);
    -ms-transform: translate(0,100%);
    -o-transform: translate(0,100%);
    transform: translate(0,100%);
}

3 个答案:

答案 0 :(得分:1)

我将使用带有模态动画的W3CSS框架,它看起来像这样,希望对您有所帮助:

HTML:

<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<button type="submit" class="btn btn-block btn-default footer__btn" data-toggle="modal" data-target="#myModal2"> Open Modal</button>
<div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content w3-animate-bottom">
      <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"> ABOUT </h4>
      </div>
      <div class="modal-body">
        CONTEÚDO
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>

      </div>
    </div>
  </div>
</div>

CSS:

.modal.fade .modal-dialog {
    -webkit-transform: translate(0,100%);
    -ms-transform: translate(0,100%);
    -o-transform: translate(0,100%);
    transform: translate(0,100%);
}

JSFiddle DEMO

答案 1 :(得分:1)

由于您不想在Bootstrap 4之上添加其他框架,因此我只更改了CSS:

.animate-bottom {
  position: relative;
  animation: animatebottom 0.4s;
}

@keyframes animatebottom {
  from {
    bottom: -300px;
    opacity: 0;
  }

  to {
    bottom: 0;
    opacity: 1;
  }
}

然后只需在animate-bottom中的modal-content之后添加类<div>

<button type="submit" class="btn btn-block btn-default footer__btn" data-toggle="modal" data-target="#myModal2"> Open Modal</button>
<div class="modal fade animate" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content animate-bottom"> <!-- Here you have the juicy hahah -->
      <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"> ABOUT </h4>
      </div>
      <div class="modal-body">
        CONTEÚDO
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>

      </div>
    </div>
  </div>
</div>

这是小提琴:

JSFiddle DEMO

确保将其制作成跨浏览器,但这只是动画的基础,希望它能满足您的要求。

答案 2 :(得分:0)

FAQ

.modal.fade .modal-dialog {
  transform: translate3d(0, 100vh, 0);
}

.modal.show .modal-dialog {
  transform: translate3d(0, 0, 0);
}