LavaLamp for jQuery lovers! August 23rd, 2007

Hover above and feel for yourself, the nifty effect of Lava Lamp. What you just experienced is nothing but the LavaLamp menu packaged as a plugin for the amazing jQuery javascript library. I personally believe that the effect rivals that of flash – Don’t you? Especially considering the fact that it is extremely light weight.

Just so you know, it weighs just 700 bytes(minified)!


Often I have noticed, that the credits are usually granted towards the end. Just for a change, i am going to give my credits at the beginning. This effect was originally written by Guillermo Rauch for the mootools javascript library. All I did was to port it for the benefit of jQuery lovers. Thanks Guillermo for inspiring the javascript world with such a nice effect. A special thanks to Stephan Beal who named it “LavaLamp”, and to Glen Lipka for generously helping with the image sprites. Many fellow jQuery lovers also helped shape this plugin with valuable feedback in the mailing list. Thanks a ton, all you guys.

As User Interface developers, we know that one of the first widgets our visitors use is a “Menu”. Capturing their attention right there is something that we always strive for, and I guess LavaLamp is a step in that direction. Before you get bored with all this useless talk, let me get you started on integrating LavaLamp into your jQuery powered site.

I hope you agree that a typical HTML widget consists of 3 distinct components.

  • A semantically correct HTML markup
  • A CSS to skin the markup
  • An unobstrusive javascript that gives it a purpose

Now lets follow the above steps and implement the LavaLamp menu for your site. Remember, In the process of porting from mootools to jQuery, i have simplified both the javascript and CSS for your convenience. So, be informed that you will need to follow the instructions on this page to get the jQuery version running. Follow the instructions on Guillermo Rauch’s page for the mootools version.

Step 1: The HTML

Since most UI developers believe that an unordered list(ul) represents the correct semantic structure for a Menu/Navbar, we will start by writing just that.

        <ul class="lavaLamp">
            <li><a href="#">Home</a></li>
            <li><a href="#">Plant a tree</a></li>
            <li><a href="#">Travel</a></li>
            <li><a href="#">Ride an elephant</a></li>
        </ul>
        

In the markup above, “ul” represents the menu, and each “li” represents a menu-item. At this point it is crucial to understand that we will be adding another artificial “li” to represent the background of the currently highlighted menu-item. Since the background itself is cosmetic and doesn’t represent a menu-item, we will be adding it from javascript. Just to make sure we are in sync, “you need not add this li”, the LavaLamp plugin will take care of it. Once added, the “li” representing the background will look like this.

        <li class="back"><div class="left"></div></li>
        

Step 2: The CSS

You can skin this markup in many different ways to achieve your own personalized menu. The following style sheet is just one possibility. A few more possibilities are demonstrated in the “Bonus” section towards the end of this blog entry.

/* Styles for the entire LavaLamp menu */
.lavaLamp {
    position: relative;
    height: 29px; width: 421px;
    background: url("../image/bg.gif") no-repeat top;
    padding: 15px; margin: 10px 0;
    overflow: hidden;
}
    /* Force the list to flow horizontally */
    .lavaLamp li {
        float: left;
        list-style: none;
    }
        /* Represents the background of the highlighted menu-item. */
        .lavaLamp li.back {
            background: url("../image/lava.gif") no-repeat right -30px;
            width: 9px; height: 30px;
            z-index: 8;
            position: absolute;
        }
            .lavaLamp li.back .left {
                background: url("../image/lava.gif") no-repeat top left;
                height: 30px;
                margin-right: 9px;
            }
        /* Styles for each menu-item. */
        .lavaLamp li a {
            position: relative; overflow: hidden;
            text-decoration: none;
            text-transform: uppercase;
            font: bold 14px arial;
            color: #fff; outline: none;
            text-align: center;
            height: 30px; top: 7px;
            z-index: 10; letter-spacing: 0;
            float: left; display: block;
            margin: auto 10px;
        }
        

Trust me, this is a simple style sheet. Follow along to understand what is done in each of its sections.

First, we style the “ul” with the bright orange background image and some basic properties like height, width, padding, margin etc. We use relative positioning because, that way we can absolutely position the background “li” relative to the “ul”. This helps by enabling us to move this background “li” freely within the context of the parent “ul”.

Next, we make the “li”s flow horizontally instead of vertically. By default, it flows vertically. There are a couple of techniques to do this. In this case, we are using the “float:left” to achieve this effect.

Next, we style the artifical “li” that represents the background of the currently highlighted menu-item. This uses the sliding doors technique. Also, notice the absolute positioning used as mentioned above.

Finally, we style the anchor that represents the actual clickable portion of each menu-item. These styles are mostly cosmetic and self-explanatory.

Some of the above rules may not be obvious if you are not very confident in how “positioning” works in CSS. For those, i highly encourage you to quickly read this article on CSS positioning. It is short, sweet and very informative.

Step 3: The Javascript

This is the easy part. Most of the javascript work is taken care by the Lava Lamp plugin itself. As a developer, you just have to include the mandatory and/or optional javascript files and fire a call to initialize the menu.

<script type="text/javascript" src="path/to/jquery.js"></script>
<script type="text/javascript" src="path/to/jquery.lavalamp.js"></script>
<!-- Optional -->
<script type="text/javascript" src="path/to/jquery.easing.js"></script>

<script type="text/javascript">
    $(function() { $(".lavaLamp").lavaLamp({ fx: "backout", speed: 700 })});
</script>
        

Include a reference to the jQuery library and the LavaLamp plugin. Optionally, include the easing plugin as well. It has many cool effects, that are not contained in the core. For instance, the “backout” effect used in this demo is part of the easing plugin. You can download jQuery here, Easing plugin here, and the LavaLamp plugin here.

Next, in the document.ready event, fire a call to initialize the menu. You have the option to supply an easing “fx” , the “speed” with which the animation happens and a callback to be executed when a menu-item is clicked. They are optional, the default “fx” being “linear” and the default “speed” being “500″ ms.

That’s it. At this point you should have a working version of LavaLamp menu for your site.

Bonus

Just with some minor changes in the style sheet, you can get a totally different look n feel for the menu. And yes, the HTML markup and the Javascript remain the same.

Here is one more variation, again with just some minor changes to the style sheet. I know, they don’t look pretty, but all i am saying is that you are limited only by your imagination.

Finally, for your convenience, i have zipped up all the necessary files into a cohesive package. Download it, and open the demo.html to see all the 3 variations in one page.

Feel free to leave a comment with your feedback, suggestions, requests etc.

Update

Based on popular request, LavaLamp Menu has been updated to support jquery 1.2.x versions. Download the zip file for version 0.2.0 of LavaLamp and open the demo.html to check it out for yourself. Since Firefox 3 has some issues with $(document).ready() function, try using $(window).load() instead if you face any problems. Hopefully a future version of Firefox or jQuery will fix the problem.

1,099 Responses to “LavaLamp for jQuery lovers!”

« 112 13 14 15 16 17 18 19 20 21 22 Show All

  1. 1051. sesli panel on January 24th, 2010 at 7:22 pm

    thank youuuu

  2. 1052. bathrooms suites on January 25th, 2010 at 12:44 am

    Completely agree with your comments on this – thanks for taking the time to post.

  3. [...] 11. Lava Lamp [...]

  4. 1054. Duffydodo on January 25th, 2010 at 9:58 am

    Hi folks,

    this lavalamp plugin is really great, but I`ve got a problem which makes me crazy.
    You can see my test page under http://www.kuskus.de/lavalamp
    It all seems fine, but the links don`t function and as a non-programmer I bet that I made an essential fault, which I am not able to see.
    It would be so kind, if s.o. could get me a hint.
    THX alot in andvance
    Duffy from Germany

  5. 1055. Duffydodo on January 25th, 2010 at 10:37 am

    aha, all tutorials concerning the lavalamp seem to be made for coders and not only poor webdesigners. So if you poor webdesigners got the same problem, change in the code below “return false” to “return true”. thats it.

    $(function() {
    $(”#1, #2, #3″).lavaLamp({
    fx: “backout”,
    speed: 700,
    click: function(event, menuItem) {
    return true;
    }
    });
    });

    now the plugin starts to make me realy happy :-)

    Duffydodo

  6. 1056. MorphList o LavaLamp per prototype « OnRails.it on January 25th, 2010 at 8:07 pm

    [...] usare il Lavalamp in uno dei nostri progetti, ma esistono due versioni una per il jQuery e una per le MooTools, peccato che io usi prototype (testato con Prototype JavaScript framework, [...]

  7. 1057. Jason on January 26th, 2010 at 1:17 am

    Thank you for the wonderful plugin!

    Also thank you Duffydodo. I spent ages looking through the Javascript code; didn’t think about even looking at the block of Javascript in my main page haha.

  8. 1058. Menu en Jquery on January 26th, 2010 at 2:16 am

    [...] Este es uno de los mejorsitos, crea un efecto “slide” muy lindo. Lavamp [...]

  9. 1059. omega watches on January 26th, 2010 at 1:49 pm

    very good!thanks for your work!

  10. 1060. halil on January 26th, 2010 at 2:13 pm

    very good! thanks…

  11. 1061. ade on January 26th, 2010 at 6:41 pm

    Hi, I tried to get this to work a while back. The effect worked great on a single page, but when I clicked from one page (say index.html with a menu item: HOME) to another page (say about.html with a menu item: ABOUT), bubble would show behind the HOME menu item on page load and not behind the ABOUT one.

    Am I missing something here?

    I’d like to get the bubble to show on page load behind ABOUT when I’m on about.html, HOME when on index.html etc.

  12. 1062. Jay on January 27th, 2010 at 12:31 am

    ade, what your trying to do is waht I wanted and I have it working, but it still adds the “.current” class to the first link. What you can do is code “.active” into the of the ACTIVE page so it becomes and then change “$li=$(”li”,this),curr=$(”li.current”,this)” in the minified JS file to “$li=$(”li”,this),curr=$(”li.active”,this)”

    the only problem is, is the .current still gets added to the home link.. and i dont know how to remove it yet.. does any1 know how to get this working the correct way? or how to remove the current link from the first li?

  13. 1063. 90 hilfreiche jQuery Plugins für Webdesigner | Photoclinique on January 27th, 2010 at 6:46 am

    [...] LavaLamp Navigation menu with a ‘lava’ effect. [...]

  14. 1064. links of london on January 27th, 2010 at 8:30 am

    cheap links of london jewellery in on hot promotions in some links of london stores among Europe. More and more fashionable ladies are rush the stores for links items like links of london pendants and links of london earrings

  15. 1065. ade on January 28th, 2010 at 4:09 am

    Hi Jay,

    I’m glad you understood what I was on about. That sounds like a way of doing it, but I’m sure there must be something simpler that we’re probably both missing.

    Surly this plugin must be meant to do what we’re wanting it too already, I think everyone using it would want it to behave like this.

    Can anyone out there help? :o )

  16. 1066. CatherinqL31 on January 28th, 2010 at 5:02 am

    The the easiest way to determine the quality of the custom thesis writing services was to order some the hottest mini dissertation about this good post from the dissertations writing services.

  17. 1067. ac?göl fm on January 28th, 2010 at 6:58 pm

    ac?gölden yay?n yapan ve ?u anda tüm dünyay? kasip kavuran bir radyo ac?göl fm herkes davetlimdir.

  18. 1068. acigol fm on January 28th, 2010 at 6:59 pm

    acigol fm acigolfm acigol fm acigolfm acigol fm acigolfm acigol fm acigolfm

  19. 1069. Ken on January 28th, 2010 at 10:16 pm

    Hi,

    Possibly stupid question, but -
    will jCarousel Lite work in wordpress selfhosted?

    Thanks

  20. 1070. jQuery?? | DesignStudio-50M?? on January 29th, 2010 at 3:27 am

    [...] jQuery SuckerFish Style. jQuery Plugin Treeview. treeView Basic. FastFind Menu. Sliding Menu. Lava Lamp jQuery Menu. jQuery iconDock. jVariations Control Panel. ContextMenu plugin. clickMenu. CSS Dock Menu. jQuery [...]

  21. 1071. Lava Lamp style Menu using jQuery « Harmeet's Design Blog on January 29th, 2010 at 5:10 am

    [...] using jQuery Very fancy style of menu design using jQuery. Gives your menu a feel like it's a Lava Lamp. Very well explained and easy to integrate [...]

  22. 1072. Medyum on January 29th, 2010 at 8:16 am

    thanks admin

  23. 1073. halil on January 29th, 2010 at 11:19 am

    this is very good. thanks

  24. 1074. hosting on January 29th, 2010 at 3:42 pm

    thank you for this article. Ive looked at the end.

  25. 1075. emre sünnet on January 29th, 2010 at 7:38 pm

    thanks for your information…

  26. 1076. hal? y?kama on January 30th, 2010 at 6:26 am

    Fantastic links, subscribed to a few of these!

  27. 1077. hali yikama on January 30th, 2010 at 6:27 am

    Fantastic links, subscribed to a few of these!

  28. 1078. Alex M on January 30th, 2010 at 9:00 pm

    thanks you!

  29. 1079. Jquery ile haz?rlanm?? men?ler - Webmaster Forumu on February 1st, 2010 at 2:15 am

    [...] [...]

  30. 1080. Kamlesh R. wagh on February 1st, 2010 at 9:26 am

    hi friend,

    i am using lavalamp menu in my project, i am giving links to menus but when i am go to “about us” page from “home” page the menu selection box is appearing on “home” link, plz gaid me how can i appear that on “about us” menu in “about us” page.

    thanks in advance
    plz reply…..

    Regards,
    Kamlesh Wagh
    Nashik, Maharashtra
    India

  31. 1081. Jose Duenas on February 1st, 2010 at 4:48 pm

    If you are using Lavalamp menu in WordPress and you want to highligth the current page item, you just have to repalce all ocurrencies for “current” in jquery.lavalamp.js to “current_page_item”.

  32. 1082. dvOdry on February 2nd, 2010 at 12:46 am

    People run to freelance writing jobs , with the purpose to some information close to this post.

  33. 1083. replica watches on February 3rd, 2010 at 10:44 am

    very good !thank you for your work!

  34. 1084. Junnel on February 4th, 2010 at 3:29 am

    May i know how to put a dropdown submenu in my main menu that will ease when i hover it.Please help. thanks…

  35. 1086. RedKoala on February 5th, 2010 at 8:19 am

    Hey Ganesh
    Big thanks for this Plugin – Lavalamp looks awesome!
    I put it on my website http://www.redkoaladesign.pl

  36. 1087. Mia26 on February 5th, 2010 at 3:38 pm

    Usually, teachers are willing to check the expository essay writing technique of their students, nevertheless not all good students are able to write professionally just because of lack of time or other issues. Thence, a essay writing service can aid to compose the term paper thesis professionally.

  37. 1088. Top 15 Jquery CSS Animated Navigation Tutorials – Designzzz on February 5th, 2010 at 6:32 pm

    [...] Demo | Tutorial [...]

  38. 1089. Theo on February 5th, 2010 at 9:55 pm

    Maybe a stupid question ? would this work on a vertical menu ?

    Thank you for sharing !

  39. 1090. Spencer on February 6th, 2010 at 2:28 am

    Hey,

    I am wondering the same thing that others on this page have asked about keeping the current page highlighted when you click the link. If anyone has a solution I would really appreciate it. Thanks

    P.S You need a better spam filter!

  40. 1091. susan on February 6th, 2010 at 7:41 am

    it is interesting and informative article. This has been very helpful understanding a lot

    of things. I’m sure a lot of other people will agree with me.

  41. 1092. alomarangoz on February 6th, 2010 at 6:11 pm

    thask

  42. 1093. chris on February 6th, 2010 at 6:11 pm

    hey thank you for this javascript it help me to release my new website
    you are so great here i have used it http://www.khoatu.de/

  43. 1094. beylerbeyi on February 6th, 2010 at 6:11 pm

    profiterol thanks

  44. 1095. LindaEx on February 6th, 2010 at 10:57 pm

    Thank you, it’s very wonderfull description it might be very helpful for students. For example last year when I had a difficult of time at the end of semester with a continual flow of academic assignments and job, I had a admirable idea to buy it somewhere and than use check for plagiarism. I was so bushed that I did not care for what can begin when my academic work was written by flipside person. To my adroitest surprise, research paper was desirable the price I paid for it. I was so charmed with the quality and now everytime i use this service.

  45. 1096. andy charrington on February 7th, 2010 at 12:24 am

    thanks a lot

  46. 1097. Creating a Fancy menu using CSS3 and jQuery | INSIC DESIGNS on February 8th, 2010 at 6:49 pm

    [...] the Mootools library. And later a jQuery version of this menu called lavalamp was made popular by Ganesh. This time I will show you how to achieve the same effect using the CSS3 new [...]

  47. 1098. Raffaell on February 8th, 2010 at 7:27 pm

    Hi…

    I’m using ur scripts as a normal scripts (not for wp or joomla).
    Now the problem is how to fix the .current issue ?
    Everytime i click the links, the position is back to the first li.

    Too many comments already and make me dizzy to find the solution.

    Thanks,
    Raff

  48. 1099. ???? on February 9th, 2010 at 5:26 am

    I just discovered this blog today. Do you have a recording of this webinar?

« 112 13 14 15 16 17 18 19 20 21 22 Show All

Leave a Reply