I just finished the Javascript Live course, and I’m dipping my toe in the water with some jQuery.
I was pretty d*mn pleased with myself for coming up with this “also works with javascript disabled” solution. (replace the class if javascript is enabled)
The lava thingie is sliding, the links light up on mouse over, everything was perfect!
And then I just discovered that when you click on a link (a href=“link.html”) nothing happens!! Tested in FF and IE.
And to make matters worse, I can’t figure out why that is. I really hope someone can help me fix this.
Not sure what standard procedure is here - should I upload this somewhere as well, or is providing the code enough?
HTML ( more divs than needed because it’s part of a bigger page…but this is ‘menu only’)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<title>title</title>
<link href="css/menu.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="scripts/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="scripts/jquery.easing.min.js"></script>
<script type="text/javascript" src="scripts/jquery.lavalamp.min.js"></script>
<script type="text/javascript" src="scripts/menuscript.js"></script>
</head>
<body>
<div id="wholepage">
<div id="menulinks">
<div id="menu">
<ul class="menu" id="navmenu">
<li><a href="link.html" title="Link" class="disabled">Link </a></li>
<li><a href="link.html" title="Link" class="disabled">Link</a></li>
<li><a href="link.html" title="Link" class="disabled">Link</a></li>
</ul>
</div>
</div>
</div>
</body>
</html>
CSS
.menu {
position: relative;
height: 30px;
width: 720px;
background-color: #008cad;
padding: 5px;
margin: 0;
overflow: hidden;
}
.menu li {
float: left;
list-style: none;
}
/*jquery adds this class */
.menu li.back{
border: 0;
background-color: #55b1ca;
width: 9px;
height: 30px;
z-index: 8;
position: absolute;
}
.menu li a.enabled, .menu li a.disabled {
font: normal 12px Geneva, Arial, Helvetica, sans-serif;
color: #c2d4d9;
text-align: center;
text-decoration: none;
padding: 12px 6px;
text-transform: uppercase;
z-index: 10;
display: block;
height: 30px;
width: auto;
position: relative;
overflow: hidden;
margin: -5px 10px;
}
.menu li a:active, .menu li a:visited {
border: 0;
}
.menu li a.disabled:hover {
background-color: #55b1ca;
color: #ffffff;
}
.menu li a.enabled:hover {
color: #ffffff;
}
JQUERY menuscript.js
// JavaScript Document
$(document).ready(function ()
{
$('.menu li a.disabled').removeClass('disabled');
$('.menu li a').addClass('enabled');
$("#navmenu").lavaLamp({
fx: "backout",
speed: 700,
click: function(event, menuItem) {
return false;
}
});
});
jquery.lavalamp.min.js
(function($){$.fn.lavaLamp=function(o){o=$.extend({fx:"linear",speed:500,click:function(){}},o||{});return this.each(function(){var b=$(this),noop=function(){},$back=$('<li class="back"><div class="left"></div></li>').appendTo(b),$li=$("li",this),curr=$("li.current",this)[0]||$($li[0]).addClass("current")[0];$li.not(".back").hover(function(){move(this)},noop);$(this).hover(noop,function(){move(curr)});$li.click(function(e){setCurr(this);return o.click.apply(this,[e,this])});setCurr(curr);function setCurr(a){$back.css({"left":a.offsetLeft+"px","width":a.offsetWidth+"px"});curr=a};function move(a){$back.each(function(){$.dequeue(this,"fx")}).animate({width:a.offsetWidth,left:a.offsetLeft},o.speed,o.fx)}})}})(jQuery);
jquery.easing.min.js
/*
* jQuery Easing v1.1 - http://gsgd.co.uk/sandbox/jquery.easing.php
*
* Uses the built in easing capabilities added in jQuery 1.1
* to offer multiple easing options
*
* Copyright (c) 2007 George Smith
* Licensed under the MIT License:
* http://www.opensource.org/licenses/mit-license.php
*/
jQuery.easing={easein:function(x,t,b,c,d){return c*(t/=d)*t+b},easeinout:function(x,t,b,c,d){if(t<d/2)return 2*c*t*t/(d*d)+b;var a=t-d/2;return-2*c*a*a/(d*d)+2*c*a/d+c/2+b},easeout:function(x,t,b,c,d){return-c*t*t/(d*d)+2*c*t/d+b},expoin:function(x,t,b,c,d){var a=1;if(c<0){a*=-1;c*=-1}return a*(Math.exp(Math.log(c)/d*t))+b},expoout:function(x,t,b,c,d){var a=1;if(c<0){a*=-1;c*=-1}return a*(-Math.exp(-Math.log(c)/d*(t-d))+c+1)+b},expoinout:function(x,t,b,c,d){var a=1;if(c<0){a*=-1;c*=-1}if(t<d/2)return a*(Math.exp(Math.log(c/2)/(d/2)*t))+b;return a*(-Math.exp(-2*Math.log(c/2)/d*(t-d))+c+1)+b},bouncein:function(x,t,b,c,d){return c-jQuery.easing['bounceout'](x,d-t,0,c,d)+b},bounceout:function(x,t,b,c,d){if((t/=d)<(1/2.75)){return c*(7.5625*t*t)+b}else if(t<(2/2.75)){return c*(7.5625*(t-=(1.5/2.75))*t+.75)+b}else if(t<(2.5/2.75)){return c*(7.5625*(t-=(2.25/2.75))*t+.9375)+b}else{return c*(7.5625*(t-=(2.625/2.75))*t+.984375)+b}},bounceinout:function(x,t,b,c,d){if(t<d/2)return jQuery.easing['bouncein'](x,t*2,0,c,d)*.5+b;return jQuery.easing['bounceout'](x,t*2-d,0,c,d)*.5+c*.5+b},elasin:function(x,t,b,c,d){var s=1.70158;var p=0;var a=c;if(t==0)return b;if((t/=d)==1)return b+c;if(!p)p=d*.3;if(a<Math.abs(c)){a=c;var s=p/4}else var s=p/(2*Math.PI)*Math.asin(c/a);return-(a*Math.pow(2,10*(t-=1))*Math.sin((t*d-s)*(2*Math.PI)/p))+b},elasout:function(x,t,b,c,d){var s=1.70158;var p=0;var a=c;if(t==0)return b;if((t/=d)==1)return b+c;if(!p)p=d*.3;if(a<Math.abs(c)){a=c;var s=p/4}else var s=p/(2*Math.PI)*Math.asin(c/a);return a*Math.pow(2,-10*t)*Math.sin((t*d-s)*(2*Math.PI)/p)+c+b},elasinout:function(x,t,b,c,d){var s=1.70158;var p=0;var a=c;if(t==0)return b;if((t/=d/2)==2)return b+c;if(!p)p=d*(.3*1.5);if(a<Math.abs(c)){a=c;var s=p/4}else var s=p/(2*Math.PI)*Math.asin(c/a);if(t<1)return-.5*(a*Math.pow(2,10*(t-=1))*Math.sin((t*d-s)*(2*Math.PI)/p))+b;return a*Math.pow(2,-10*(t-=1))*Math.sin((t*d-s)*(2*Math.PI)/p)*.5+c+b},backin:function(x,t,b,c,d){var s=1.70158;return c*(t/=d)*t*((s+1)*t-s)+b},backout:function(x,t,b,c,d){var s=1.70158;return c*((t=t/d-1)*t*((s+1)*t+s)+1)+b},backinout:function(x,t,b,c,d){var s=1.70158;if((t/=d/2)<1)return c/2*(t*t*(((s*=(1.525))+1)*t-s))+b;return c/2*((t-=2)*t*(((s*=(1.525))+1)*t+s)+2)+b},linear:function(x,t,b,c,d){return c*t/d+b}};