Can Twitter Bootstrap alerts fade in as well as out?

前端 未结 10 496
夕颜
夕颜 2020-12-07 09:28

When I first saw the alerts in Bootstrap I thought they would behave like the modal window does, dropping down or fading in, and then fading out when closed. But it seems li

10条回答
  •  情书的邮戳
    2020-12-07 10:15

    Add hide class to alert-message. Then put the following code after your jQuery script import:

    $(document).ready( function(){
        $(".alert-message").animate({ 'height':'toggle','opacity':'toggle'});
        window.setTimeout( function(){
            $(".alert-message").slideUp();
        }, 2500);
    });
    

    If you want handle multiple messages, this code will hide them in ascending order:

    $(document).ready( function(){
       var hide_delay = 2500;  // starting timeout before first message is hidden
       var hide_next = 800;   // time in mS to wait before hiding next message
       $(".alert-message").slideDown().each( function(index,el) {
          window.setTimeout( function(){
             $(el).slideUp();  // hide the message
          }, hide_delay + hide_next*index);
       });
    });
    

提交回复
热议问题