Skip to content

Instantly share code, notes, and snippets.

@ecto
Created March 13, 2012 03:21
Show Gist options
  • Select an option

  • Save ecto/2026384 to your computer and use it in GitHub Desktop.

Select an option

Save ecto/2026384 to your computer and use it in GitHub Desktop.
express-messages fader
;(function () {
var el = document.getElementById('messages');
if (!el) return;
var fade;
var start;
var c = 100;
var fps = 100;
var wait = 1000;
var duration = 3000;
var mt = duration / fps; // max ticks
var opt = 100 / mt; // opacity delta per tick
set(100);
function paint () {
var now = +new Date - start;
if (now >= duration) {
set(0);
return clearInterval(fade);
}
c -= opt;
set(c);
}
function set (o) {
el.style.opacity = o / 100;
el.style.filter = 'alpha(opacity=' + o + ')';
}
setTimeout(function () {
start = +new Date;
fade = setInterval(paint, fps / 1000);
}, wait);
})();
@ecto
Copy link
Copy Markdown
Author

ecto commented Mar 13, 2012

When using express-messages, you can put this guy in your template and it will fade flash messages with pure javascriptz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment