gpt4 book ai didi

jquery - Bootstrap 4 选项卡动画

转载 作者:行者123 更新时间:2023-12-03 22:55:52 24 4
gpt4 key购买 nike

我正在尝试为 Bootstrap 4 导航上的选项卡 Pane 设置动画。

这是我的示例代码:

.tab-pane {
transform: translateY(100%);
transition: transform 2s;
}
.tab-pane.active {
transform: translateY(0%);
}
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" type="text/css">

<nav class="nav nav-tabs" id="myTab" role="tablist">
<a class="nav-item nav-link active" id="nav-home-tab" data-toggle="tab" href="#nav-home" role="tab" aria-controls="nav-home" aria-selected="true">Home</a>
<a class="nav-item nav-link" id="nav-profile-tab" data-toggle="tab" href="#nav-profile" role="tab" aria-controls="nav-profile" aria-selected="false">Profile</a>
<a class="nav-item nav-link" id="nav-contact-tab" data-toggle="tab" href="#nav-contact" role="tab" aria-controls="nav-contact" aria-selected="false">Contact</a>
</nav>
<div class="tab-content" id="nav-tabContent">
<div class="tab-pane active" id="nav-home" role="tabpanel" aria-labelledby="nav-home-tab">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
<div class="tab-pane" id="nav-profile" role="tabpanel" aria-labelledby="nav-profile-tab">
type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
<div class="tab-pane" id="nav-contact" role="tabpanel" aria-labelledby="nav-contact-tab">
It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
</div>

理论上,每个选项卡 Pane 中的文本应该来自底部,但每次我更改选项卡时,我都会发现它位于最终位置。我对这个设置肯定有一些不明白的地方,有人能告诉我我做错了什么吗?

最佳答案

这里的问题是,没有 .active 类的 .tab-pane 设置了 display: none;,但是 css 转换却设置了 display: none;从该状态转换时不起作用。

所以你有两个选择:

  • 您可以覆盖 Bootstrap 处理非事件选项卡的方式,并且您可以使用 - 比方说 - 可见性属性来显示/隐藏选项卡,而不是使用显示属性。只需确保强制执行 display: block 即可。
  • 更简单的解决方案是简单地使用带有关键帧的 css 动画,而不是 css 过渡。前一种解决方案适用于显示;也没有。下面的例子就是一个例子。

.tab-pane.active {
animation: slide-down 2s ease-out;
}

@keyframes slide-down {
0% { opacity: 0; transform: translateY(100%); }
100% { opacity: 1; transform: translateY(0); }
}
<nav id="myTab" class="nav nav-tabs" role="tablist">
<a class="nav-item nav-link active" id="nav-home-tab" data-toggle="tab" href="#nav-home" role="tab" aria-controls="nav-home" aria-selected="true">Home</a>
<a class="nav-item nav-link" id="nav-profile-tab" data-toggle="tab" href="#nav-profile" role="tab" aria-controls="nav-profile" aria-selected="false">Profile</a>
<a class="nav-item nav-link" id="nav-contact-tab" data-toggle="tab" href="#nav-contact" role="tab" aria-controls="nav-contact" aria-selected="false">Contact</a>
</nav>

<div class="tab-content" id="nav-tabContent">
<div class="tab-pane active" id="nav-home" role="tabpanel" aria-labelledby="nav-home-tab">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>

<div class="tab-pane" id="nav-profile" role="tabpanel" aria-labelledby="nav-profile-tab">
type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>

<div class="tab-pane" id="nav-contact" role="tabpanel" aria-labelledby="nav-contact-tab">
It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
</div>


<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js"></script>

关于jquery - Bootstrap 4 选项卡动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47970932/

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