gpt4 book ai didi

jquery - 动画下拉菜单 Bootstrap 4

转载 作者:技术小花猫 更新时间:2023-10-29 12:04:46 25 4
gpt4 key购买 nike

下拉菜单在 bootstrap (4.0) 中的原生方式不是动画。我怎样才能让它像导航栏折叠时那样“滑动”打开?

值得注意的是,下拉菜单位于导航栏内。请参阅下面的代码; https://www.codeply.com/go/JKj5onR3ug

<nav class="navbar navbar-dark bg-dark">
<a class="navbar-brand" href="#">Never expand</a>
<button class="navbar-toggler collapsed" type="button" data-toggle="collapse" data-target="#navbarsExample01" aria-controls="navbarsExample01" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>

<div class="navbar-collapse collapse" id="navbarsExample01" style="">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="dropdown01" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Dropdown</a>
<div class="dropdown-menu" aria-labelledby="dropdown01">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</li>
</ul>
</div>
</nav>

最佳答案

下面是我如何使用 transform: scale 用纯 css 制作下拉动画:

SCSS 风格

.dropdown {
.dropdown-menu {
transition: all 0.5s;
overflow: hidden;
transform-origin: top center;
transform: scale(1,0);
display: block;
}
&:hover {
.dropdown-menu {
transform: scale(1);
}
}
}

查看 Codepen 上的演示

关于jquery - 动画下拉菜单 Bootstrap 4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50022112/

25 4 0