JQuery is a great javascript platform that developers can use to add spice to their pages. Lavalamp was originally created for mootools and was converted over by Ganesh.
First, get the JQuery, Lavalamp and Easing libraries
(4kb) jquery.easing.1.1.js (Click to download)
(4kb) jquery.lavalamp.js (Click to download)
Step 1:
Insert these files into the head tags on your page:
1 2 3 | <script type="text/javascript" src="path/to/jquery.js"></script> <script type="text/javascript" src="path/to/jquery.lavalamp.js"></script> <script type="text/javascript" src="path/to/jquery.easing.js"></script> |
Step 2:
Now add this to the head of your page as well:
1 2 3 | <script type="text/javascript"> $(function() { $(".lavaLamp").lavaLamp({ fx: "backout", speed: 700 })}); </script> |
Step 3:
Now were going to start inserting the html and css. Lets start by adding the menu itself, then add in the finishing touches. Now, put this where you want your menu to appear:
1 2 3 4 5 6 | <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> |
Step 4:
Now open your stylesheet and add this css. Remember, this is where you can create the look and feel of your nav.
This example uses two images, you can have them both here: lavabg.gif and lava.gif.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | /* Styles for the entire LavaLamp menu */ .lavaLamp { position: relative; height: 29px; width: 421px; background: url("../image/lavabg.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; } |
Now you should have a working menu that will give your site an edge while looking great! This also shows how JQuery can really compete with flash, while being very lightweight.

20 Users Responded in " Lavalamp sliding navigation menu "
I tried this example and everything works great. Except when I add real links. When I click a link it is no longer selected. The selection defaults to the Home button. How can I change this to where the link selected will be active depending on which link I click on?
Thanks in advanced.
@Aaron
The reason why this is happening is because each time the page reloads, it will also reload the menu. So, you’ll want to add the “current” style to which nav item you want to be “selected” on a given page, like this:
Thanks for the response. I understand that a class would need to be added, but is there a way to make the class dynamic depending on which tab is selected so more than one header wouldn’t need to be created?
I’ve been trying to figure this out, and for some reason, it’s pretty difficult to find an example of this online. If you know of any resources I may not be aware of for this I would love to know!
Yes, and it would be to use additional code (this capability is not built into lavalamp and I don’t really think it could be, because each website would be different). There would be many ways to do this, the easiest would be using php. The php code for this would vary greatly depending on how your back-end is setup (if one at all). Are you using a popular back-end system? Generally, this type of functionality is already built in.
hello
i have downloaded Lavalamp sliding navigation menu from http://www.gmarwaha.com/blog/2007/08/23/lavalamp-for-jquery-lovers/
I have encountered a problem when placing a url in the href in the menu list of demo.html
It does not open any url. Can some1 explain to why?thanks for ur help
Greetings Vineet,
Please look at step2 of this tutorial. It should be similar to the one you downloaded. Either use my code in step2, or look for a “return: false;”. Remove that, and it should work great.
step 2 will fix it perfectly.
Ok, probably a really stupid question but here goes. I am using your awesome script and the way that I have my new website set up is using the pagescroll technique. I am not very good with javascript as of yet although I seem to have gotten everything with your script set up ok. I used the “current” value to place the “box” over the cooresponding link based upon what “page” we are at (I have several navigation menus within the site). But because all of the “pages” are actually just anchors, when I go to my profile “page”, the box is over the correct link but when I go from that page back to the home “page”, the box there is still over the profile link. And at that point, if I were to go back to the profile “page” then the box is now positioned over the home link. So basically what I am trying to accomplish, is after one clicks on the “page” they want to go to, the box always goes back to the link with the “current” class applied. Does that make sense? lol.
Here’s a link so you can see what I mean:
http://www.ideologydesign.com/new/
Thanks bro!
Andrew,
You’ll probably want to send an ajax request after a click to reset the “current” value.
Cheers,
Brandon
This is nice but it have some limite.bcz its not wors on internet Explorer 6.very sad.wish fix that problem very soon.
Very nice code. I used it on a wordpress theme I am currently developing. Way to go man.
Hi!
I´m using the Lavalamp sliding menu on the same page as a jCarousel but it dont work together. When I´m not loading the “jquery.easing.min.js” the Carousel works but not the animation in the menu. Why is there a conflict? And what can I do to solve the problem?
You can view the page here, http://www.yatzy.se/om
am i the only one that is having cross-browser issues? I installed the standard orange lavalamp and in IE everything is fine. Newer versions of Firefox however makes a right mess of it… Anybody had the same experience?
Is there a way to have the “current” font color different, yet have it change to another color when the menu is being used? Like, once the background moves to another link, the “current” link changes color.
I have integrated this menu in Typo3. You want to know how to do it? Ask me at xtraklaus@arcor.de
thank you for sharing.
much appreciated
@vineet Comment out return false;. It works.
EG:
$(function() {
$(”#1, #2, #3″).lavaLamp({
fx: “backout”,
speed: 700,
click: function(event, menuItem) {
// return false;
}
});
});
Heloo Brandon Fredericksen,
First of all I would like to thank you for spending your time to share this wonderful information, which helps beginers like me..
I did not understand, How to create current active class for the below css and html. I would be very thankful If you could do so..
//CSS//
.lavaLamp {
position: relative;
height: 36px;
width: 740px;
padding:4px 0 0 0;
margin: 0;
overflow: hidden;
}
.lavaLamp li {
float: left;
list-style: none;
}
.lavaLamp li.back {
width: 9px;
height: 36px;
background:none repeat scroll 0 0 rgba(0, 0, 0, 0.3);
border-radius:10px;
-moz-border-radius:10px;
-webkit-border-radius:10px;
behavior:url(”");
z-index: 8;
position: absolute;
}
.lavaLamp li a {
height: 36px;
float: left;
color: #fff;
margin: auto 10px;
font: bold 15px cursive;
text-align: center;
text-decoration: none;
outline: none;
top: 6px;
letter-spacing: 0;
z-index: 10;
display: block;
position: relative;
overflow: hidden;
}
.lavaLamp li a:hover, .lavaLamp li a:active, .lavaLamp li a:visited {
border: none;
}
//HTML//
Home
About
Archive
Lab
Reviews
Contact
//HTML//
Home
About
this is my site… you can see the view here…
Thank you in Advance.
Mohd,
You need to use PHP to identify the “current” page. Something similar to this (this is just one way to do this, there are many ways) …
URL defines the variable ‘$page’: http://www.yoursite.com/index.php?page=home
//get the variable page$current = $_GET['page'];
//is the Home page set? if so, set li class to current.
if ($current == "Home"){
<li class="current">
<a href="http://www.2mellow.com" rel="nofollow">Home</a>
</li>
} else {
<li>
<a href="http://www.2mellow.com" rel="nofollow">Home</a>
</li>
}
Leave A Reply Here