Flash message fade effect

前端 未结 2 1519
一生所求
一生所求 2020-12-30 02:07

I\'m trying to use a flash message with a fade in and out effect using jQuery. can someone please suggest the best way of doing this?

相关标签:
2条回答
  • 2020-12-30 02:49

    This is a modification of Jacob's answer above. You can't fade in something that isn't hidden initially.

    Instructions:

    put an id of flash into your flash message, like this (my flash messages are stored here app/views/layouts/_flashmessages.html.erb):

    <% flash.each do |key, value| %>
        <div class="well lead" id="flash"><%= value %></div>
    <% end %>
    

    make a new file called assets/javascripts/flash.js.coffee

    put this in (beware of spaces, make sure all indentations are tabs):

    jQuery ->
    
        $('#flash').hide().delay(800).fadeIn(800).delay(4000).fadeOut(800)
    
    0 讨论(0)
  • 2020-12-30 02:50

    Sure:

    $(function() {
       $('#flash').delay(500).fadeIn('normal', function() {
          $(this).delay(2500).fadeOut();
       });
    });
    

    jsFiddle example

    0 讨论(0)
提交回复
热议问题