Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flash message fade effect

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?

like image 451
chaz hamilton Avatar asked Jan 26 '11 05:01

chaz hamilton


2 Answers

Sure:

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

jsFiddle example

like image 163
Jacob Relkin Avatar answered Oct 23 '22 09:10

Jacob Relkin


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)
like image 23
Pavan Katepalli Avatar answered Oct 23 '22 09:10

Pavan Katepalli