Reputation: 1888
Is there a way to make dismissed alert in bootstrap have an animation like fade out?
I added the class .fade
to the code:
<div class="alert alert-info fade alert-dismissable">
<p><b>Gracias</b> por ponerte en contacto! Responderé a tu correo lo más pronto posible.</p>
</div>
But it doesn't work. Any help will be appreciated!
Upvotes: 14
Views: 26755
Reputation: 2430
You can listen to close.bs.alert
event to use custom effects:
$(function(){
$('body').on('close.bs.alert', function(e){
e.preventDefault();
e.stopPropagation();
$(e.target).slideUp();
});
});
See in action at https://jsfiddle.net/6s8dgh72/8/
Upvotes: 2
Reputation: 421
you can add '.in' class, alert fade out.
<div class="alert alert-info fade in">
<a class="close" data-dismiss="alert" href="#">×</a>
<p>message</p>
</div>
Upvotes: 42
Reputation: 812
you can omit the data-dismiss attribute
<div class="alert alert-warning alert-dismissable">
<button type="button" class="close" aria-hidden="true">×</button>
<p>animated dismissable</p>
</div>
and use the following jQuery
$(".alert button.close").click(function (e) {
$(this).parent().fadeOut('slow');
});
or if you want clicking anywhere to close the alert use
$(".alert-dismissable").click(function (e) {
$(this).fadeOut('slow');
});
Upvotes: 9
Reputation: 12571
$('.alert-dismissable').fadeOut();
or assign a css3 fade out animation to your fade class and apply it to the <div>
when you want it to fade out.
Upvotes: 3