【问题标题】:Bootstrap 4 collapse has delayBootstrap 4 崩溃有延迟
【发布时间】:2018-03-02 19:05:43
【问题描述】:

我正在移动视图上创建画布导航菜单,我遇到了一个问题,即在添加类 .show 之前有 0.3 秒的延迟。

我尝试通过 jquery 添加自定义类 .active 但结果是相同的 - 即使没有延迟添加该类,该类的转换仍然延迟。

.collapse.active{
  transform: translateX(0%);
}

这很可能是由于添加和计算我并不真正需要的内联样式高度造成的,因为我一直希望 nav 为 100vh。有没有办法减少或加快计算部分?

尝试添加此代码,但完全没有帮助。

.collapsing {
-webkit-transition: all 0s ease-out;
-o-transition: all 0s ease-out;
transition: all 0s ease-out;
height:0 !important;
display: none;
}

Bootply 链接(有延迟):https://www.bootply.com/9dFOT7Q2Ct

我在 codepen 上做了同样的事情,它工作得很好 - 它甚至没有向 #navbarNav 添加内联样式,所以可能是 jquery 问题(我正在使用推荐的 jquery-3.2.1)

Codepen 链接(由于某种原因没有延迟):https://codepen.io/janheder/pen/rGLJLb

【问题讨论】:

    标签: javascript jquery css twitter-bootstrap navigation


    【解决方案1】:

    您可能会遇到延迟,因为引导程序在 show 之前添加了一个 collapsing 类到导航栏以提供对动画的更多控制。

    如果您正在寻找平稳过渡,我相信这可能会有所帮助: https://www.bootply.com/rPqvbgcCVj

    body {
      overflow-x: hidden;
      -webkit-transition: margin .3s ease;
      -moz-transition: margin .3s ease;
      -o-transition: margin .3s ease;
      transition: margin .3s ease;
      width: 100%;
      margin: 0;
      font-family: -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        Roboto,
        "Helvetica Neue",
        Arial,
        sans-serif;
      font-size: 1rem;
      font-weight: 400;
      line-height: 1.5;
      color: #212529;
      background-color: #fff;
    }
    
    .navbar-light .navbar-nav .nav-link {
      padding-right: 1.5rem;
      padding-left: 1.5rem;
      position: relative;
    }
    
    .navbar .menu-item.menu-item-has-children > .nav-link:after {
      content: "";
      width: 0;
      height: 0;
      border-style: solid;
      position: absolute;
      right: 0;
      top: 50%;
      -ms-transform: translateY(-50%);
      -webkit-transform: translateY(-50%);
      transform: translateY(-50%);
      border-width: 4px 4px 0px 4px;
      border-color: #007bff transparent transparent transparent;
    }
    /* Added the following code and removed previous code */
    .collapsing {
      transform: translateX(0%);
    }
    
    @media (max-width: 991px) {
      body.active {
        overflow: hidden;
        height: 100%;
        width: 100%;
        margin-left: -280px;
      }
      .collapse.active {
        transform: translateX(0%);
      }
    
      .navbar-collapse {
        position: fixed;
        right: 0px;
        top: 0px;
        display: block;
        transform: translateX(100%);
        height: 100vh;
        width: 280px;
        transition: transform .3s ease;
        overflow-y: scroll;
        background: #fff;
      }
      /* Added the following code */
      .active.collapsing {
        transform: translateX(0%);
      }
    
    
      .navbar .menu-item.menu-item-has-children > .nav-link:after {
        right: 1.5rem;
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2017-10-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-09
      • 2017-02-24
      相关资源
      最近更新 更多