Skip to content

Instantly share code, notes, and snippets.

@Langmans
Created January 9, 2015 15:53
Show Gist options
  • Save Langmans/9652c4f0cf938fcf0212 to your computer and use it in GitHub Desktop.
Save Langmans/9652c4f0cf938fcf0212 to your computer and use it in GitHub Desktop.
auto close bootstrap alerts
(function () {
var timeout = 0;
$('.alert').each(function () {
var
$alert = $(this),
text = $alert.text().replace(/(^\s+|\s+$)/, ''),
num_lines = $alert.height() / parseFloat($alert.css('line-height')),
num_words = text.split(/\s{2,}/).length,
// 120 words per minute and add a second for each line.
seconds = (num_words / 120 * 60) + num_lines;
timeout += (seconds * 1000);
setTimeout(function () {
$alert.alert('close');
}, timeout);
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment