Created
March 13, 2012 03:21
-
-
Save ecto/2026384 to your computer and use it in GitHub Desktop.
express-messages fader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;(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); | |
| })(); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When using express-messages, you can put this guy in your template and it will fade flash messages with pure javascriptz