Bootstrap 4中从底部滑出的模态框

4
我正在尝试设置一个从底部滑动的模态框,但是没有适用于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个回答

5

既然您不想在Bootstrap 4之上添加另一个框架,那么我只更改了CSS:

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

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

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

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

<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,链接如下:JSFiddle DEMO。请确保实现跨浏览器效果,这只是动画的基础,希望它能满足你的要求。

1

基于这个答案

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

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

0
我会使用带有模态动画的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演示


谢谢,但这加载了不同的CSS文件,并且不是从下面滑动。 - Elaine Byene
1
你可以将"w3-animate-top"更改为"w3-animate-bottom",W3CSS代码的完整列表在这里:https://www.w3schools.com/w3css/w3css_modal.asp。 - mattdaspy
1
再次感谢您,但正如我所说,我不想在Bootstrap 4之上添加另一个框架。 - Elaine Byene

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接