I strongly disagree with most of the answers mentioned earlier.
Short answer:
Omit the "in" class and add it using jQuery to quench it.
See this jsfiddle for an example that disappears in alert state after 3 seconds http://jsfiddle.net/QAz2U/3/
Long answer:
Although it is true that bootstrap does not support fading in warnings, most of the answers here use the fade jQuery function, which uses JavaScript to animate (erase) an element. The big advantage of this is cross-browser compatibility. The downside is performance (see Also: jQuery to invoke CSS3 fade animation? ).
Bootstrap uses CSS3 transitions that have better performance. What is important for mobile devices:
Download CSS to display a warning:
.fade { opacity: 0; -webkit-transition: opacity 0.15s linear; -moz-transition: opacity 0.15s linear; -o-transition: opacity 0.15s linear; transition: opacity 0.15s linear; } .fade.in { opacity: 1; }
Why do I think this performance is so important? People using older browsers and hardware will potentially get jerky transitions with jQuery.fade (). The same goes for older hardware with modern browsers. Using CSS3 transitions, people using modern browsers will get smooth animation even with old equipment, and people using old browsers that do not support CSS transitions will just instantly notice that an element has entered it, which, in my opinion, is more convenient for the user than volatile animation.
I came here to find the same answer as above: to disappear in the bootstragg. After some digging in the code and CSS Bootstrap, the answer is pretty simple. Do not add the in class to your alert. And add this using jQuery when you want to disappear in your warning.
HTML (note that there is no NO in the class!)
<div id="myAlert" class="alert success fade" data-alert="alert"> </div>
JavaScript:
function showAlert(){ $("#myAlert").addClass("in") }
The function call above the function adds the "in" class and disappears in the notification using CSS3 transitions :-)
Also see this jsfiddle for an example using a timeout (thanks John Lehmann!): Http://jsfiddle.net/QAz2U/3/
DivZero Nov 06 '12 at 19:05 2012-11-06 19:05
source share