First jQuery Plugin

2011-11-22

I wrote my first jQuery plugin. It’s nothing fancy, but I’ve got the boilerplate down for future plugins.

Thanks to jMar for the jump start.

(function($){
 $.fn.truncate = function() {                    ////truncate is the name of the plugin
    var defaults = {                             ////set up default parameters
         ////default values here
    };
    var options = $.extend(defaults, options);   ////options will be the parameter scope
    return this.each(function() {                ////loop through each matched element

    });
 };
})(jQuery);

My plugin takes containers and horizontally spaces all images they contain. I built it for the images across the top of my web site. It could definitely be expanded upon. Currently, it only takes a width option (default: 120) and only works horizontally.

Regardless, you can check it out here.

Written on November 22, 2011