我正在 MEAN 堆栈中构建网站。我正在使用 animate.css,虽然动画很干净,但文档并不完全清楚。说明是“只需加水”,即只需添加动画类和您想要的特定动画类型的类。我有一个模态,内置在 jquery 中,如下所示:
var listModal = '<!-- Modal -->'+
'<div id="testModal'+ v.id +'" class="testModal modal animated flipInX fade" tabindex="-1" role="dialog" aria-labelledby="'+ v.id +'-label" aria-hidden="true">'+
'<div class="modal-backdrop fade"></div>'+
'<div class="modal-dialog modal-lg">'+
'<div class="modal-content">'+
'<div class="modal-header testModalBar">'+
'<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>'+
'<h4 class="test4 modal-title" id="'+ v.id +'-label"> '+ v.client +'</h4>'+
'</div>'+
'<div class="modal-body">'+
'<h3 class="test3">'+ v.title +'</h3>'+
'<div class="row">'+
'<div class="col-md-6">'+
'<h5 class="test"> Challenge: </h5>'+
'<p id="challengeText">'+ v.challenge +'</p>'+
'<h5 class="test"> Solution: </h5>'+
'<p id="challengeText">'+ v.solution +'</p>'+
'<h5 class="test"> Return: </h5>'+
'<p id="challengeText">'+ v.ret +'</p>'+
'</div>'+
'<div class="col-md-6">'+
'<img src="/images/'+ v.img +'" alt="">'+
'</div>'+
'</div>'+
'</div>'+
'<div class="modal-footer">'+
'<button id="testBtn'+ v.id +'" type="button" class="btn btn-sm btn-default" data-dismiss="modal">Close</button>'+
'</div>'+
'</div>'+
'</div>'+
'</div>'+
'<!-- Modal end -->';
flipInX 动画和淡入淡出动画配合得非常好,但我似乎无法让任何接近的动画正常工作。我试过只添加类,我试过通过 hide.bs.modal 和 hidden.bs.modal 事件在模态的关闭事件上添加关闭动画类,如下所示:
$("testModal" + v.id).on("hide.bs.modal", function (e) {
$("#testModal" + v.id).addClass("flipOutY");
});
$("testModal" + v.id).on("hidden.bs.modal", function (e) {
$("#testModal" + v.id).removeClass("flipOutY");
});
这是行不通的。静态添加类不起作用。如何使用 Bootstrap 模式和 animate.css 成功地合并结束动画?
最佳答案
bootstrap modal animation open/close with animate.css
$('.modal').on('show.bs.modal', function (e) {
$('.modal .modal-dialog').attr('class', 'modal-dialog fadeIn animated');
})
$('.modal').on('hide.bs.modal', function (e) {
$('.modal .modal-dialog').attr('class', 'modal-dialog fadeOut animated');
})
关于javascript - Animate.css 与 Bootstrap 模态的交互,关闭动画的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32314755/