Simeon Franklin

Sample colorfade plugin

This is the simplest possible well formed and useful plugin... Should be in file called jquery.colorfade.js (following the jquery.mypluginname.js convention).


// Note dependencies in comments: js has no built-in dependency/module system

// NOTE: requires jquery color plugin

(function($){
    $.fn.colorfade = function(opts){
	// Provide configurability and document
	var defaults =	    {'target': '#FF0', // Color to animate too
			     'reset': '#FFF', // Reset color
			     'delay': 500, // Length of pause between animations
			    }
	var conf = $.extend(defaults, opts);
	this.animate({'background-color': conf.target})
	    .delay(conf.delay)
	    .animate({'background-color': conf.reset});
	return this; // maintain chainability
    }
})(jQuery)// call anonymous outer function passing it jquery object