Accomplishing This Style of Drop-Down Menus in jQuery

Posted by Maxim Z. on Stack Overflow See other posts from Stack Overflow or by Maxim Z.
Published on 2010-05-08T18:32:40Z Indexed on 2010/05/08 18:38 UTC
Read the original article Hit count: 301

Filed under:
|
|
|
|

I was browsing the web and found this site. I noticed how the nav bar drop-down works, and I want to implement something similar on my website.

Afer going into the source code of the page, I found that those drop-down areas are contained in divs with class fOut.

It turns out that this is being done with MooTools. Here is the script itself (referenced in the original page after the Mootools script itself):

window.addEvent('domready', function() {


    $("primaryNav").getChildren("li").addEvents({
        "mouseenter": function(){
            $(this).addClass("hover").getChildren("a").addClass("hover");
        },
        "mouseleave": function(){
            $(this).removeClass("hover").getChildren("a").removeClass("hover");
        }
    });

    $$(".fOut").each(function(el,i){
        var ifr = $(document.createElement("iframe"));
        ifr.className = "ieBgIframe";
        ifr.frameBorder = "0";
        ifr.src="about:blank";

        ifr.injectInside(el);
        var p = el.getParent();
        p.addClass("hover");
        var h = el.getSize().size.y;
        p.removeClass("hover");
        ifr.height=h;
    });

    $$(".olderVersionsToggle").addEvents({
        "click": function(e){

            var event = new Event(e);
            event.stop();

            var p = $(this).getParent().getNext();

            if(p.hasClass("open")){
                p.removeClass("open");
                $(this).setText("Show previous versions...");
            }
            else{
                p.addClass("open");
                $(this).setText("Hide previous versions...");
            }


            return false;

        }
    });


});

My Question(s)

I have two questions about this code.

  1. How does it work? I don't quite understand what it's doing, with the iframes and all.
  2. How can this be implemented in jQuery?

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about mootools