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,425 Responses to “LavaLamp for jQuery lovers!”

« 113 14 15 16 17 18 19 20 21 22 2329 » Show All

  1. 851. BandonRandon on October 16th, 2009 at 2:26 am

    I see by default the first menu item is selected is there a way to override this right now my solution is to create a li with a class of “blank” which no text and have that selected but it’s sort of a messy solution.

    Brooke

  2. 852. 13???CSS+Javascript?? | I'm Bolo on October 16th, 2009 at 2:51 pm

    [...] LavaLamp jQuery ???? ? ?? jQuery ????? ???LavaLamp jQuery ???? ??? Mootools Fancy [...]

  3. 853. crousti on October 16th, 2009 at 11:45 pm

    Does anybody know how to fix the bug in ie6 ? It’s not working so bad on ie6, that’s surprising but maybe could be better..?

  4. 854. 26 jQuery Plugins for Superb Navigation | Master Design on October 18th, 2009 at 3:41 am

    [...] 6. LavaLamp for jQuery lovers! [...]

  5. 855. ZachMagic on October 19th, 2009 at 7:56 pm

    Hey, i’m implamenting this on Blogger. It works fine but it doesn’t set the current list item correctly.
    http://www.Left4DeadSafeRoom.com
    Any solutions?

  6. 856. ZachMagic on October 20th, 2009 at 12:42 pm

    I thought the lavalamp.js did that for you?

  7. 857. ZachMagic on October 20th, 2009 at 1:36 pm

    so do i just need to write some javascript to check the url and set the current list item based on that?

  8. [...] Read the original here: LavaLamp for jQuery lovers! | Ganesh [...]

  9. 859. Tutoriais e demos de menus em JQuery | idealMind on October 21st, 2009 at 1:05 am

    [...] Lavalamp menu Muito bacana esse menu: você passa o mouse sobre o itens e uma animação é exibida para destacar o item que o mouse está por cima. Possui diversos exemplos. Tutorial & Demo [...]

  10. 860. Kristeen on October 21st, 2009 at 10:09 pm

    What if I want one of the other links to start as the first page selected?

    For example I want “plant a tree” to be highlighted w/o the user actually having to click on it first.

    Any help would be greatly appreciated!

  11. 861. Perry on October 23rd, 2009 at 2:37 pm

    I’ve got the dame problem with the lins that are not working… What’s the solution for this?

    Thanks for any help.

  12. 862. Tony on October 23rd, 2009 at 8:42 pm

    Is there a conflict with this lavalamp and the prettybox lightbox?

  13. 863. Collection of 30+ AJAX Menu Plugins - DoNotYet.com on October 25th, 2009 at 1:14 pm

    [...] Flash like menu rollover using jQuery [...]

  14. 864. Les on October 25th, 2009 at 6:36 pm

    I have implemented a this on my site and works great but the li images don’t render in any version of IE. I thought I might have done a typo, but couldn’t find any. Anyone els have this problem?

  15. 865. Des centaines de liens JQuery | Juste le zeste... on October 27th, 2009 at 2:54 pm

    [...] 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. [...]

  16. 866. Plugins jQuery para Menús | Daniel on October 28th, 2009 at 1:10 am

    [...] 5.- LavaLamp [...]

  17. 867. NFL jerseys on October 28th, 2009 at 8:46 am
  18. 868. ugg boots on October 28th, 2009 at 8:47 am
  19. 869. hürriyet ilan on October 28th, 2009 at 10:08 am

    your good comment

  20. 870. 10 incredible JQuery navigation menus | Programming Blog on October 28th, 2009 at 7:43 pm

    [...] Lavalamp is a simple, ready to use JQuery plugin which allow you to create a stunning effect over your horizontal navigation bars. Nice to see, easy to implement. Source [...]

  21. 871. Diego on October 29th, 2009 at 12:43 am

    Do you realize that the links are not working? you actually can not follow the links with this… i thought i was doing something wrong, but if you click even in this site on one link it doesnt follow… i should get the # on nav bar.. not getting it.. not working

  22. 872. Diego on October 29th, 2009 at 12:56 am

    OMG i feel so stupid right now!! i didn’t notice de callback returning false , THANKS FOR THIS AWESOME MENU!!!

  23. 873. Jeff on October 29th, 2009 at 1:44 am

    Is there a way that I can have it hover over the current page I am on? Example: I am on the about page, I would like the “lava” to hover over the about page link.

    Any suggestions?

    Other than that I love it.

    Thanks!

  24. 874. chiangmai guide and tour on October 29th, 2009 at 7:21 am

    thank for share tips. myblog is chiangMai guide and tour

  25. 875. iyifikir on October 29th, 2009 at 8:49 am

    links don’t work

  26. 877. 50 Cool CSS Menus, Free Source Codes + Tutorials on October 30th, 2009 at 6:35 am

    [...] 27. LavaLamp Menu [...]

  27. 878. Dave on October 31st, 2009 at 10:40 am

    Thanks, got this working nicely. But how can I increase the gap between the words but keep it so the image still only highlights the word. I have tried adding padding but the image then highlights the gap aswell :(

    Please help!

  28. 879. CHROMAX on November 2nd, 2009 at 5:44 pm

    It does not work with the newest easing 1.3, only with 1.1

  29. 880. 240??jQuery?? | Jidda's Blog on November 4th, 2009 at 8:44 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 [...]

  30. 881. 13????Javascript?CSS??? | ?? - CoolShell.cn on November 4th, 2009 at 11:19 am

    [...]   8 ) LavaLamp jQuery ???? [...]

  31. 882. Anthony on November 4th, 2009 at 3:30 pm

    In response to 902, I believe http://gsgd.co.uk/sandbox/jquery/easing/jquery.easing.compatibility.js fixes the issue with easing 1.3.

  32. 883. erick on November 4th, 2009 at 6:23 pm

    Dear friends, your menu is great but the links does not work… thanks

  33. 884. Vincio on November 4th, 2009 at 8:36 pm

    At Anthony 906: that library doesn’t solve the problem with the version 1.3 :\
    For me it doesn’t work :(

  34. 885. ???? on November 5th, 2009 at 7:34 am

    that library doesn’t solve the problem with the version

  35. 886. wow gold on November 5th, 2009 at 7:35 am

    SuckerFish Style. jQuery Plugin Treeview. treeView Basic. FastFind Menu. Sliding Menu. Lava Lamp jQuery Menu.

  36. [...] Demo Visit [...]

  37. 888. jQuery menu « Open Source on November 7th, 2009 at 9:52 pm

    [...] [...]

  38. 889. jQuery plugins | blogmw on November 10th, 2009 at 1:42 am

    [...] download i dokumentacja [...]

  39. [...] 2. Lava Lamp Menu Library: jQuery Source: http://www.gmarwaha.com/blog/2007/08/23/lavalamp-for-jquery-lovers/ [...]

  40. 892. Crossfit Dixie | J Man Design Group on November 11th, 2009 at 4:18 am

    [...] so Wordpress was used in this instance in its most simplistic and original approach.We used jQuery LavaLamp script for the navigation animation. It was very easy to implement and has a nice small footprint. [...]

  41. 893. Haisheng HU on November 11th, 2009 at 6:58 am

    It seems no work in IE7.
    IE6, IE8, FF are all okay.

  42. 894. propecia for sale on November 11th, 2009 at 8:56 am

    nifty effects – really nice!

  43. 895. flamingbanjo on November 12th, 2009 at 10:55 pm

    I really like this. However, I’d like to modify it so that the menu box defaulted to a position over the page that the user is currently on. I’m thinking of using a php variable to set the value of the li element to “selected” (or something like that), but I’m curious if you’ve addressed this issue already. Does the select box always have default to the far left?

  44. 896. Robi Santoso on November 13th, 2009 at 7:46 am

    Thanks for your post…
    I tried another version of lavalamp. but it’s make a conflict with my another jquery plugin..
    But…I tried your script for fixing my bug…And..It’s Fixed…

    Thank U very much…

  45. 897. Jquery Lovers on November 13th, 2009 at 5:05 pm

    I hope you could accept my request.Because I am a jquery lovers ,too .After I have found out about horizontal lavalamp .I don ‘t know how to make a vertical lavalamp.I was wondering if you could continue making vertical lavalamp for everybody who is just beginners as me ?

    I hope you could give me an opportunity to see your ability on the gmarwaha website. please.

  46. 898. Romuald on November 13th, 2009 at 6:43 pm

    I’m french, so i don’t speak english very well and i’m a jquery lover
    but i like this plugins, thank !!

  47. 899. film izle on November 14th, 2009 at 11:37 am
  48. 900. Curacao on November 14th, 2009 at 4:17 pm

    [quote]Step 3: The Javascript

    This is the easy part. [/quote]

    Fuck you!

« 113 14 15 16 17 18 19 20 21 22 2329 » Show All

Leave a Reply