如何在一段时间后关闭 Rails 闪存消息? [英] How do I dismiss a Rails flash message after some duration?

查看:51
本文介绍了如何在一段时间后关闭 Rails 闪存消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设置显示flash通知的秒数在它被自动关闭之前,给用户.

I would like to set the number of seconds a flash notice is shown to the user, before it is automatically dismissed.

推荐答案

你可以在你的页面上使用一些简单的 JavaScript(在这个例子中使用 jQuery):

You can use some simple JavaScript on your page (using jQuery in this example):

$('document').ready(function() {
  setTimeout(function() {
    $('#flash').slideUp();
  }, 3000);
});

假设保存您的 flash 消息的 HTML 元素的 id 是 #flash,这会将其向上滑动并在 3000 毫秒(3 秒)后隐藏.

Assuming the id of the HTML element holding your flash message is #flash, this will slide it up and hide it after 3000 milliseconds (3 seconds).

这篇关于如何在一段时间后关闭 Rails 闪存消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆