【问题标题】:Boostrap 4 dropmenu Animation starts from outside the pageBootstrap 4下拉菜单动画从页面外开始
【发布时间】:2019-10-31 01:18:20
【问题描述】:

我有一行包含两个 div,一个是 col-md-11,另一个是 col-md-1。在这个 col-md-1 div 中,我有一个需要动画的下拉菜单。对于动画,我使用animate css,但问题是动画 slideInRight 从页面外部开始。我希望动画应该从不在下面页面之外的行边界开始是我的 html

    <div class="row m-0">
<div class="col-md-7">
</div>
<div class="col-md-5 text-right">
<div class="btn-group">
  <button type="button" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown" data-display="static" aria-haspopup="true" aria-expanded="false">
    Right-aligned
  </button>
  <div class="dropdown-menu dropdown-menu-right dropdown-menu-lg-left animated slideInRight" style="width:500px;">
    <button class="dropdown-item" type="button">Action</button>
    <button class="dropdown-item" type="button">Another action</button>
    <button class="dropdown-item" type="button">Something else here</button>
  </div>
</div>
</div>

</div>

在这个动画 slideInRight 类中提供滑入的动画。

【问题讨论】:

    标签: html css animation bootstrap-4


    【解决方案1】:

    在这个答案中,我在您的问题中使用了更新的代码,并对 animate.css 代码和 Bootstrap4 drop-down 项目进行了必要的修改,以便最终结果更符合我理解的规定要求:

    CSS

    .animated {
      -webkit-animation-duration: 1s;
      animation-duration: 1s;
      -webkit-animation-fill-mode: both;
      animation-fill-mode: both;
    }
    
    @-webkit-keyframes slideInRight {
      from {
        -webkit-transform: translate3d(9rem, 2rem, 0);
        transform: translate3d(9rem, 2rem, 0);
        visibility: visible;
      }
    
      to {
        -webkit-transform: translate3d(0, 2rem, 0);
        transform: translate3d(0, 2rem, 0);
      }
    }
    
    @keyframes slideInRight {
      from {
        -webkit-transform: translate3d(9rem, 2rem, 0);
        transform: translate3d(9rem, 2rem, 0);
        visibility: visible;
      }
    
      to {
        -webkit-transform: translate3d(0, 2rem, 0);
        transform: translate3d(0, 2rem, 0);
      }
    }
    
    .slideInRight {
      -webkit-animation-name: slideInRight;
      animation-name: slideInRight;
    }
    
    .dropdown-item {
        height: 2rem !important;
        margin-bottom: 1rem !important;
        padding: 1rem !important;
        width: 25rem !important;
    }
    

    此解决方案具有完全的适应性,如果您想完成它,我很乐意与您合作:)

    重要细节:

    • Bootstrap 4 类 text-rightdropdown-menu-lg-left 是 不相容。菜单按钮在任何情况下都不会向左移动 如果text-right 被添加到col-md-5

    • 我更改了translate3d 的“y”属性,以便slideInRight 出现在按钮下方。如果您愿意,则无​​需进行此更改 menu-item 在按钮滑入时覆盖它。如果你想 更改它,然后 所有引用translate3d 应该有 'y' 元素放回 0:

      translate3d(9rem, 2rem, 0); 将变为 translate3d(9rem, 0, 0); 对所有对translate3d 的引用进行了类似的更改。

    • 我更改的dropdown-item 属性也演示了 在不使用内联样式的情况下该元素的适应性(如 用你以前版本的代码写的)。

    我希望这个答案对 Feroz 有所帮助。如前所述,我很乐意与您合作完成满足您要求的解决方案。 :)

            .animated {
              -webkit-animation-duration: 1s;
              animation-duration: 1s;
              -webkit-animation-fill-mode: both;
              animation-fill-mode: both;
            }
            
            @-webkit-keyframes slideInRight {
              from {
                -webkit-transform: translate3d(9rem, 2rem, 0);
                transform: translate3d(9rem, 2rem, 0);
                visibility: visible;
              }
    
              to {
                -webkit-transform: translate3d(0, 2rem, 0);
                transform: translate3d(0, 2rem, 0);
              }
            }
    
            @keyframes slideInRight {
              from {
                -webkit-transform: translate3d(9rem, 2rem, 0);
                transform: translate3d(9rem, 2rem, 0);
                visibility: visible;
              }
    
              to {
                -webkit-transform: translate3d(0, 2rem, 0);
                transform: translate3d(0, 2rem, 0);
              }
            }
    
            .slideInRight {
              -webkit-animation-name: slideInRight;
              animation-name: slideInRight;
            }
            
            .dropdown-item {
                height: 2rem !important;
    			      margin-bottom: 1rem !important;
                padding: 1rem !important;
                width: 25rem !important;
            }
    <!doctype html>
    <html lang="en">
      <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">    
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
    
      </head>
      
      <body>
    
          <!-- <div class="container"> -->
              
              <div class="row m-0">
                  <div class="col-md-7"></div>
                  <div class="col-md-5">
                      <div class="btn-group">
                          <button type="button" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown" data-display="static" aria-haspopup="true" aria-expanded="false">
                              Right-aligned
                          </button>
                          <div class="dropdown-menu dropdown-menu-right dropdown-menu-lg-left animated slideInRight" style="">
                              <button class="dropdown-item" type="button">Action</button>
                              <button class="dropdown-item" type="button">Another action</button>
                              <button class="dropdown-item" type="button">Something else here</button>
                          </div>
                      </div>
                  </div>
              </div>
              
          <!-- </div> -->
    
    	
    	<!-- javascript -->
        <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
      
      </body>
    </html>

    【讨论】:

    • Feroz _ 我也有一个在线解决方案的功能模型,以展示对@media 查询的响应能力
    • 我注意到你问了另一个关于animate.cssFeroz 的问题 _ 如果你找不到合适的插件,也许可以创建一个你需要的小动画库?
    猜你喜欢
    • 2018-10-05
    • 1970-01-01
    • 2019-10-14
    • 2017-09-28
    • 1970-01-01
    • 1970-01-01
    • 2019-06-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多