javascript Flash 消息淡入淡出效果
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/4801561/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Flash message fade effect
提问by chaz hamilton
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?
我正在尝试使用具有淡入淡出效果的 Flash 消息使用jQuery. 有人可以建议这样做的最佳方法吗?
回答by Jacob Relkin
Sure:
当然:
$(function() {
   $('#flash').delay(500).fadeIn('normal', function() {
      $(this).delay(2500).fadeOut();
   });
});
回答by Pavan Katepalli
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 id 放入您的 flash 消息中,如下所示(我的 flash 消息存储在 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
创建一个名为 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)

