我使用twitter的bootstrap CSS框架(这是太棒了)。对于一些消息给用户,我使用警告Javascript JS和CSS显示它们。
I'm using twitter's bootstrap CSS framework (which is fantastic). For some messages to users I am displaying them using the alerts Javascript JS and CSS.
对于感兴趣的用户,可以在这里找到: http:// getbootstrap。 com / javascript /#alerts
For those interested, it can be found here: getbootstrap/javascript/#alerts
我的问题是这样的;在我向用户显示提醒后,我希望它在一段时间间隔后离开。基于twitter的文档和我看过的代码看起来这不是在:
My issue is this; after I've displayed an alert to a user I'd like it to just go away after some time interval. Based on twitter's docs and the code I've looked through it looks like this is not baked in:
- 我的第一个问题是请求确认这确实没有进入Bootstrap
- 其次,如何实现这种行为?
调用window.setTimeout (function,delay) 将允许您完成此操作。下面是一个在显示警报后2秒(或2000毫秒)自动关闭警报的示例。
Calling window.setTimeout(function, delay) will allow you to accomplish this. Here's an example that will automatically close the alert 2 seconds (or 2000 milliseconds) after it is displayed.
$(".alert-message").alert(); window.setTimeout(function() { $(".alert-message").alert('close'); }, 2000);如果你想把它包装在一个nifty函数中,你可以这样做。
If you want to wrap it in a nifty function you could do this.
function createAutoClosingAlert(selector, delay) { var alert = $(selector).alert(); window.setTimeout(function() { alert.alert('close') }, delay); }然后你可以这样使用...
Then you could use it like so...
createAutoClosingAlert(".alert-message", 2000);我确定有更多优雅的方法来完成这个。
I am certain there are more elegant ways to accomplish this.
更多推荐
如何使用Twitter Bootstrap自动关闭警报
发布评论