【问题标题】:Modal to slide up from bottom in Bootstrap 4在 Bootstrap 4 中从底部向上滑动的模态
【发布时间】:2019-09-29 02:26:39
【问题描述】:

我正在尝试设置一个从底部向上滑动的模式,但没有真正有效的 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%);
}

【问题讨论】:

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


    【解决方案1】:

    由于您不想在 Bootstrap 4 之上添加另一个框架,我只是更改了 CSS:

    .animate-bottom {
      position: relative;
      animation: animatebottom 0.4s;
    }
    
    @keyframes animatebottom {
      from {
        bottom: -300px;
        opacity: 0;
      }
    
      to {
        bottom: 0;
        opacity: 1;
      }
    }
    

    然后在&lt;div&gt;中的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 DEMO

    确保你让它跨浏览器,但这只是动画的基础,希望它符合你的要求。

    【讨论】:

      【解决方案2】:

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

      【讨论】:

      • 谢谢,但这会加载不同的 CSS 文件,并且不会从下方向上滑动。
      • 您可以将 w3-animate-top 更改为 w3-animate-bottom,W3CSS 代码的完整列表在这里:w3schools.com/w3css/w3css_modal.asp
      • 再次感谢您,但就像我说的,我不想在 bootstrap 4 之上添加另一个框架。
      【解决方案3】:

      Based on this answer:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-10-04
        • 1970-01-01
        • 1970-01-01
        • 2021-10-22
        • 2012-08-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多