Skip to content

Instantly share code, notes, and snippets.

@Radagaisus
Created December 20, 2011 03:49
Show Gist options
  • Save Radagaisus/1500144 to your computer and use it in GitHub Desktop.
Save Radagaisus/1500144 to your computer and use it in GitHub Desktop.
Yellow Fade Technique in Coffee
# $(".something").yellow_fade(1000)
# underscore.js is used. adapted from http://amix.dk/blog/post/19029
(($) ->
$.fn.yellow_fade = (speed) ->
# we call this function repeatedly
decrease_fade = (e, i, speed) ->
shades = ['ff', 'ee', 'dd', 'cc', 'bb', 'aa', '99']
if i # i == 0
e.css 'backgroundColor', "#ffff#{shades[i]}"
_.delay decrease_fade, speed, e, i-1, speed
else
e.css 'backgroundColor', 'transparent'
@each ->
decrease_fade $(@), 6, speed
)(jQuery)
# Javascript:
(function($) {
$.fn.yellow_fade = function(speed) {
var decrease_fade = function(e, i, speed) {
var shades = ['ff', 'ee', 'dd', 'cc', 'bb', 'aa', '99'];
if (i) {
e.css('backgroundColor', "#ffff" + shades[i]);
_.delay(decrease_fade, speed, e, i - 1, speed);
} else {
e.css('backgroundColor', 'transparent');
}
};
return this.each(function() {
decrease_fade($(this), 6, speed);
});
}})(jQuery)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment