Flash消息 - jQuery [英] Flash Message - jQuery
问题描述
在我的Rails应用程序中,我有闪存消息,我希望每次有闪存消息时,它从顶部向下滚动(所有内容变低)停留几秒钟,幻灯片重新启动。
In my Rails application I have flash messages and I would like it so that each time there is a flash message, it scrolls down from the top (all the content goes lower) stays for a few seconds and the slides back up.
如何使用jQuery执行此操作?
How can I do this with jQuery?
我是否切换高度?
有时会将消息注入HTML,这意味着 slideDown
因为DOM已经加载了将无法工作,我怎么能拥有它以便jQuery查找 .message
然后应用 slideDown
和 slideUp
?
Sometimes the message will be injected into the HTML which means that the slideDown
won't work since the DOM has already loaded, how can I have it so jQuery looks for .message
and then applies the slideDown
and slideUp
?
推荐答案
你可以做到向下滑动,等待几秒钟并再次滑回:
You can make it slide down, wait for couple of seconds and slide back again with this:
$(selector for your message).slideDown(function() {
setTimeout(function() {
$(selector for your message).slideUp();
}, 5000);
});
将 5000
更改为您想要的时间消息以毫秒为单位保持可见。
Change the 5000
to the time you want the message to stay visible in milliseconds.
并记得在CSS中为您的消息设置 display:none;
,所以直到jQuery进入才会出现。
And remember to set display: none;
in CSS for your message, so that it does not appear until jQuery goes in.
这篇关于Flash消息 - jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!