gpt4 book ai didi

twitter-bootstrap - 在 Bootstrap 4 中自定义折叠过渡

转载 作者:行者123 更新时间:2023-12-04 02:11:30 26 4
gpt4 key购买 nike

Bootstrap 4 使用类 .collapsing在打开/关闭它时为 .collapse-element 的宽度/高度设置动画。不幸的是,实际更改是通过将宽度/高度作为内联样式添加到元素并在过渡的开始和结束时添加和删除类来实现的。因此自定义过渡非常困难(例如更改时间或淡入/淡出而不是宽度过渡)。

到目前为止我已经尝试过:

  • 添加css属性transition:none.collapsing类:这确实有助于摆脱过渡,但打开/关闭仍会因过渡时间而延迟,因为在实际更改发生之前,类仍会添加几毫秒。
  • 将自定义 CSS 关键帧添加到 .collapsing class:由于打开和关闭使用相同的类,因此两者显示相同的动画。

  • 有什么方法可以改变过渡,例如淡入/淡出(改变不透明度)还是我必须构建 bootstrap.js 的自定义版本?

    最佳答案

    看看这个例子:

    .collapse {
    visibility: hidden;
    }
    .collapse.show {
    visibility: visible;
    display: block;
    }
    .collapsing {
    position: relative;
    height: 0;
    overflow: hidden;
    -webkit-transition-property: height, visibility;
    transition-property: height, visibility;
    -webkit-transition-duration: 0.35s;
    transition-duration: 0.35s;
    -webkit-transition-timing-function: ease;
    transition-timing-function: ease;
    }
    .collapsing.width {
    -webkit-transition-property: width, visibility;
    transition-property: width, visibility;
    width: 0;
    height: auto;
    }
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
    <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet"/>
    <div class="container">
    <div class="row">
    <div class="col-md-6">
    <button role="button" class="btn btn-danger" data-toggle="collapse" data-target="#demo">
    horizontal collapse
    </button>
    <div id="demo" class="collapse show width">
    <div style="width:400px;">
    <p>Works smoother when element has defined width. Egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p>
    <p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p>
    </div>
    </div>
    </div>
    <div class="col-md-6">
    <button role="button" class=" btn btn-danger" data-toggle="collapse" data-target="#demo2">
    vertical collapse
    </button>
    <div id="demo2" class="collapse show">
    <div>
    <p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p>
    <p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p>
    </div>
    </div>
    </div>
    </div>
    </div>

    关于twitter-bootstrap - 在 Bootstrap 4 中自定义折叠过渡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47738975/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com