Saturday, November 1, 2008

[jQuery] Re: New plugin: jquery.smoothDivScroll-0.5.js

>     All improvements and suggestions are welcome!

Some quick comments on the code itself, not the implementation, just
the technical bits:

1.) Your plugin is not chainable. The plugin function should 'return
this' to honor jQuery's chaining model. For example, this will fail:
$('div').smoothDivScroll().parent().show();

2.) Your plugin code is written with the assumption that a single
element has been selected. But in reality your $mom variable could
represent a set of elements if I call your plugin like this: $
('div').smoothDivScroll();
Based on what I see in the code I'm pretty sure this will not work as
expected. What you need inside the plugin is an iteration loop so
that you can loop over each selected element:
this.each(function() {
// treat each item in here as a 'mom'
}

3.) There are several places in the code where you use a document-
ready handler - $(function(... - but it's safe to assume that your
plugin is invoked within a document-ready handler, and so these
functions you defined will execute immediately. In other words, you
can just run those bits of code w/o the 'ready'.

Nice work on the demo and the write-up. The results look rather nice.

More plugin tips can be found here:
http://docs.jquery.com/Plugins/Authoring
http://www.learningjquery.com/2007/10/a-plugin-development-pattern
http://malsup.com/jquery/conf08/

Cheers!

Mike

No comments: