Flash message fade effect

前端 未结 2 1540
一生所求
一生所求 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| %>
        
    <%= value %>
    <% 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)
    

提交回复
热议问题