Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide Bootstrap modal with fade out effect using Javascript

I have a basic bootstrap modal to log in, which doesn't close itself when I hit submit. I solved it using this simple jquery:

$('#myModal').modal('hide');

But I also want the modal to fade out properly using bootstrap's fade class - which currently doesn't happen, it instantly gets hidden.

How can I do this?

like image 594
Florian Bienefelt Avatar asked Oct 27 '25 14:10

Florian Bienefelt


2 Answers

$('#myModal').delay(1000).fadeOut(450);

 setTimeout(function(){
    $('#myModal').modal("hide");
 }, 1500);
like image 63
floooat Avatar answered Oct 29 '25 02:10

floooat


You can pass the duration of the fade effect to the fadeout function. then pass a callback function as a second parameter. In the body of the callback function, you then hide the modal window

   $('#myModal').fadeOut(500,function(){
                $('#myModal').modal('hide');
             });
like image 39
Yannick Y Avatar answered Oct 29 '25 04:10

Yannick Y



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!