Register now or login here to start promoting your blog and your favourite articles.
jQuery Horizontal Tooltips Menu Tutorials
21 Aug 2009 - 9 Comments
A horizontal menu with tooltip that slides accross the menu panel. It's a bit similar to lava lamp, but in this script, it displays the caption of the icon menu.
Author: kevin | Source: queness
Demonstration Download

Introduction

Last week, we have gone through How to make a Lava Lamp Menu Tutorial, now, we're doing something a little bit similar - Tooltips menu.

You will need jQuery easing plugin for the animated transition. This is how it looks like:

Tooltips Menu

1. HTML

As usual, it's a good practise to use UL List for menu. For the menu images, you need to put the caption in the ALT attribute, because jQuery will look at the ALT for it.

For #box div, we're creating a self-expandable tooltips, the length of the tooltip will expand according to the size of the content. This is the chart to show how we're going to achieve it.

Create a self-expandable tooltips

2. CSS

I have added inline comment in the following CSS code. If you want to learn more about CSS, read my previous post 15 CSS Tips and Tricks.

	body {
		font-family:georgia; 
		font-size:14px; 
	}
	
	a {
		text-decoration:none; 
		color:#333;
		outline:0;
	}
	
	img {
		outline:0; 
		border:0;
	}
	
	#menu {
		/* you must set it to relative, so that you can use absolute position for children elements */
		position:relative; 
		text-align:center; 
		width:583px; 
		height:40px;
	}
	
	#menu ul {
		/* remove the list style and spaces*/
		margin:0; 
		padding:0; 
		list-style:none; 
		display:inline;
				
		/* position absolute so that z-index can be defined */
		position:absolute; 
		
		/* center the menu, depend on the width of you menu*/
		left:110px; 
		top:0; 
		
	}
	
	#menu ul li {
		
		/* give some spaces between the list items */
		margin:0 5px; 
		
		/* display the list item in single row */
		float:left;
	}
	
	#menu #box {
		
		/* position absolute so that z-index can be defined and able to move this item using javascript */
		position:absolute; 
		left:0; 
		top:0; 
		z-index:200; 

		/* image of the right rounded corner */
		background:url(tail.gif) no-repeat right center; 
		height:35px;


		/* add padding 8px so that the tail would appear */
		padding-right:8px;
		
		/* set the box position manually */
		margin-left:5px;
		
	}
	
	#menu #box .head {
		/* image of the left rounded corner */
		background:url(head.gif) no-repeat 0 0;
		height:35px;
		color:#eee;
		
		/* force text display in one line */
		white-space:nowrap;

		/* set the text position manually */
		padding-left:8px;
		padding-top:12px;
	}

3. Javascript

Javascript is pretty straight forward, the calculation isn't that hard either. So, once it's executed, it does the following things:

  1. Calculate the left value
  2. Grab the default value from the selected item
  3. Set the left, top and the caption to the box

On mouse over:

  1. Calculate the left value
  2. Grab the current item caption
  3. Set the left, top and the caption to the box

On mouse leave:

  1. Calculate the left value
  2. Grab the default value from the selected item
  3. Set the left, top and the caption to the box
	
$(document).ready(function () {

	//transitions
	//for more transition, goto http://gsgd.co.uk/sandbox/jquery/easing/
	var style = 'easeOutExpo';
	var default_left = Math.round($('#menu li.selected').offset().left - $('#menu').offset().left);
	var default_top = $('#menu li.selected').height();

	//Set the default position and text for the tooltips
	$('#box').css({left: default_left, top: default_top});
	$('#box .head').html($('#menu li.selected').find('img').attr('alt'));				
		
	//if mouseover the menu item
	$('#menu li').hover(function () {
		
		//get the left pos	
		left = Math.round($(this).offset().left - $('#menu').offset().left);

		//Set it to current item position and text
		$('#box .head').html($(this).find('img').attr('alt'));
		$('#box').stop(false, true).animate({left: left},{duration:500, easing: style});	

		
	//if user click on the menu
	}).click(function () {
		
		//reset the selected item
		$('#menu li').removeClass('selected');	
		
		//select the current item
		$(this).addClass('selected');

	});
	
	//If the mouse leave the menu, reset the floating bar to the selected item
	$('#menu').mouseleave(function () {

		//get the left pos
		default_left = Math.round($('#menu li.selected').offset().left - $('#menu').offset().left);

		//Set it back to default position and text
		$('#box .head').html($('#menu li.selected').find('img').attr('alt'));				
		$('#box').stop(false, true).animate({left: default_left},{duration:1500, easing: style});	
		
	});
	
});

Conclusion

Like this tutorials? You can express your gratitude by visiting my sponsors on the sidebar, buy me a drink in the bottom of the page or, just bookmark it and help me to spread this tutorial to the rest of the people who you think they are interested! :) Thanks!

Demonstration Download

Copyright & Usage

The effects and techniques demonstrated in tutorials on Queness can be used in whatever manner you wish without attribution. You cannot copy whole tutorials (unless permission is given), either in English or translated to another language.

Share This Post to Support Me! :)


Comments

TutsValley.com on 20 Aug 2009 says:
Nice one. Love it. Thanks :)
Masoud on 21 Aug 2009 says:
nice job !

but i finde a little bug on galleris, chek it !

it\s better to add some extra animations when the new text is add to tooltip.

thanks for share bro :))
ฟรี mp3 on 7 Sep 2009 says:
Nice.
thiago on 8 Sep 2009 says:
pretty cool.
Mia on 16 Dec 2009 says:
Loved this as much as the Digg styled tooltip :) Beautiful K -
shoaib on 9 Jan 2010 says:
this is just superb ,and u made it loook really simple as hell,thnx
Operation Technology on 24 Jan 2010 says:
Nice article. We are actually implementing this JQuery functionality for unifying multiple sites into one portal site.
Sade on 26 Jan 2010 says:
Its a great artcile. Nice jo, thx.
jardel goiaba on 27 Jan 2010 says:
legal esse tutorial em mas tá precisando de mais exlicação! merda!

Leave a comment

http://
Subscribe RSS Subscribe RSS, Keep yourself updated with queness latest posts!
Pixel Crayons Buy and Sell Flash Buy and Sell Flash

Buy wholesale computers directly from China at DHgate.com

Discover the tools to build your e-Commerce Site with Netfirms

  •  
  •  
  •  
  •  
  •  

Community News

Recent Comments

Random Posts


View all posts and news Back to top

About the Author

A web designer and developer who is passionate and keen on contributing to the web development industry. Feel free to say hi to me, or follow me on twitter.

Kevin Liew

Partner

  • Web and Designers
  • CSS Style
  • PV.M Garage Blogzine - (Italian)
  • TutsValley
  • Designrfix
  • CoolVibe
  • Web Developer Juice
  • Denbagus
  • Web Hosting Secret Revealed
  • PSD to HTML Conversion
  • BlueHost