Hi,

I have some improvements for your script:

1. You add opacity to the ul. This opacity should be removed at mouseout.
2. Instead of using find('ul'), you shoul use children('ul'). If you
have a li with no ul, your version will open the ul of the first li
with ul.

Here is the improved code:

// enhanced suckerfish-style menu plugin by Joel Birch, edited by Mathias Bank

(function($){
$.fn.superfish = function(o){
        var defaults = {
                hoverClass      : "sfhover",
                delay           : 500,
                animation       : {"opacity":"show"},
                downAnimation: {"opacity":"hide"},
                speed           : "normal",
                downSpeed       : "fast"
        };
        var over = function(){
                var $$ = $(this);
                clearTimeout(this.sfTimer);
                if (!$$.is("."+o.hoverClass)) {
                        $$.addClass(o.hoverClass)
                                .children("ul").animate(o.animation,o.speed)
                                        .end()
                                .siblings().removeClass(o.hoverClass);
                }
        };
        var out = function(){
                var $$ = $(this);
                this.sfTimer=setTimeout(function(){$$.removeClass(o.hoverClass)
                                                                        
.children("ul")
                                                                        
.animate(o.downAnimation,o.downSpeed)
                                                                        .end();
                                                                        },
                                                                o.delay);
        };      
        o = $.extend(defaults, o || {});
        $("li[ul]",this)
                .hover(over,out)
                .find("a")
                        .focus(function(){ 
$(this).parents("li[ul]").each(over); })
                        .blur(function(){ $(this).parents("li[ul]").each(out); 
});
        return this;
};

})(jQuery);

Mathias

2007/3/9, Joel Birch <[EMAIL PROTECTED]>:
> On 10/03/2007, at 5:56 AM, Brice Burgess wrote:
> > Joel,
> >
> >   I wrote those reviews/changes @ 4am, and after more thought realize
> > most of them were unnecessary. The original code would work @ multiple
> > menus at once without the return this.each(...); The reasons I began
> > with that is I wanted to do my "serializing" within the .each
> > statement,
> > instead of the "over" function (at first). Also, as for settimeout
> > returning an integer instead of a referencing function, this would
> > eliminate the need for the serializing in the first place -- unless of
> > course, you want to attach more data to the element (such as item
> > specific timeout values, effects, etc).
> >
> >   As for attaching your functions over/out functions to the jQuery
> > object -- I would not do this... unless you need them available
> > globally. Having them within the scope of the plugin is more
> > appropriate.
> >
> > ~ Brice
>
> Well, an extra thank you for taking time @ 4am to respond! I learnt a
> lot from your advice regardless of whether it turned out to be the
> way to go or not. Just for closure (not the JS kind), here is the
> beginnings of a demo page (which I also did at 4am last night!)
> showing the plugin working not only with 3 levels of heading without
> having to change a thing (I was surprised!) but also on multiple .nav
> elements using one call to the plugin.
> http://users.tpg.com.au/j_birch/plugins/superfish/
>
> Thanks again Brice.
>
> Joel.
>
> _______________________________________________
> jQuery mailing list
> discuss@jquery.com
> http://jquery.com/discuss/
>

_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

Reply via email to