【问题标题】:Modifying Bootstrap 3's Collapse Animation with Animate.css使用 Animate.css 修改 Bootstrap 3 的折叠动画
【发布时间】:2023-03-21 00:20:02
【问题描述】:
我设法覆盖了 Bootstrap 3 的折叠插件的默认“折叠”动画,但无法覆盖切换回动画。
基本上我希望它淡入(现在正在这样做)并在关闭时淡出,目前它默认为该事件的默认 BS 动画。
例如jsfiddle
<div class="collapse animated fadeIn" id="collapseExample">
<div class="well">
...
</div>
</div>
【问题讨论】:
标签:
twitter-bootstrap-3
animate.css
【解决方案1】:
在查看了Bootstrap 3 documentation for "collapse" 和This other question 之后,我接管了这些活动并设法让它发挥作用。
- 我从元素中删除了所有 animate.css 类。
- jQuery 覆盖 BS 生成的显示和隐藏事件。
- 创建一个会延迟“隐藏”转换的类。
结果jsfiddle
JS
$(function() {
var animateIn = 'animated fadeIn';
var animateOut = 'animated fadeOut collapsing-delay';
$('#collapseExample').on('show.bs.collapse', function () {
// do something…
$(this).addClass(animateIn).on('shown.bs.collapse',
function() {
$(this).removeClass(animateIn);
});
})
$('#collapseExample').on('hide.bs.collapse', function () {
// do something…
$(this).addClass(animateOut).on('hidden.bs.collapse',
function() {
$(this).removeClass(animateOut);
});
})
})
CSS
.collapsing-delay {
/* delay BS transition for animated fadeOut to show */
-webkit-transition-delay: 2s !important;
transition-delay: 2s !important;
}