Still playing with it maybe:
Code:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title> - jsFiddle demo</title>
<script type='text/javascript' src='http://code.jquery.com/jquery-1.8.2.js'></script>
<style type='text/css'>
#menu a {
border-bottom: solid #4E9BDA 4px;
padding: 10px 25px 10px 25px;
margin: 2px;
display: block;
background: #465153;
color: #8DBFE7;
float: right;
text-decoration: none;
font-family:Georgia, "Times New Roman", Times, serif;
font-size:12px;
}
#menu a:hover {
color: #eee;
border-bottom: solid #000 4px;
}
</style>
<script type='text/javascript'>//<![CDATA[
// When the DOM is ready, initialize the scripts.
jQuery(function( $ ){
var $b = $('body');
$('#menu a').each(function(){
var $t = $(this), o = $t.offset(), $c = $('<div></div><div></div>').prependTo($b);
$c.css({position: 'absolute', top: o.top, left: o.left, width: $t.outerWidth(), height: $t.outerHeight(), backgroundColor: $t.css('backgroundColor')})
.eq(0).css({backgroundColor: $t.css('borderBottomColor')});
$t.css({position: 'relative', backgroundColor: 'transparent'}).data('hover', $c.eq(1));
}).hover(function(){
$(this).data('hover').animate({height: 0}, {duration: 900, queue: false});
}, function(){
var $t = $(this);
$t.data('hover').animate({height: $t.outerHeight()}, {duration: 900, queue: false});
});
});
//]]>
</script>
</head>
<body>
<div id="menu">
<a href="index.html">Home</a>
<a href="about.html">About</a>
<a href="projects.html">Projects</a>
</div>
</body>
</html>
Questions or Comments?
Edit: OK, I did play around with it and using the jQuery UI we can animate the colors for smoother transitions for them:
Code:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title> - jsFiddle demo</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<style type='text/css'>
#menu a {
border-bottom: solid #4E9BDA 4px;
padding: 10px 25px 10px 25px;
margin: 2px;
display: block;
background: #465153;
color: #8DBFE7;
float: right;
text-decoration: none;
font-family:Georgia, "Times New Roman", Times, serif;
font-size:12px;
}
#menu a:hover {
border-bottom: solid #000000 4px;
}
</style>
<script>
// When the DOM is ready, initialize the scripts.
jQuery(function($){
var duration = 900, $b = $('body');
$('#menu a').each(function(){
var $t = $(this), o = $t.offset(), $c = $('<div></div><div></div>').prependTo($b);
$c.css({position: 'absolute', top: o.top, left: o.left, width: $t.outerWidth(), height: $t.outerHeight(), backgroundColor: $t.css('backgroundColor')})
.eq(0).css({backgroundColor: $t.css('color')});
$t.css({position: 'relative', backgroundColor: 'transparent'}).data({hover: $c.eq(1), color: $t.css('color'), bbcolor: $t.css('borderBottomColor')});
}).hover(function(){
$(this).animate({color: '#000000'}, {duration: duration, queue: false}).data('hover').animate({height: 0}, {duration: duration, queue: false});
}, function(){
var $t = $(this), color = $t.data('color'), bbcolor = $t.data('bbcolor');
$t.css({borderBottomColor: '#000000'}).animate({color: color, borderBottomColor: bbcolor}, {duration: duration, queue: false, complete: function(){
$t.css({borderBottomColor: ''});}})
.data('hover').animate({height: $t.outerHeight()}, {duration: duration, queue: false});
});
});
</script>
</head>
<body>
<div id="menu">
<a href="index.html">Home</a>
<a href="about.html">About</a>
<a href="projects.html">Projects</a>
</div>
</body>
</html>
Note: IE 8 and less require UI version 8x. 9x is available but will break this in IE 8 and less.
Bookmarks