Home Tutorials Fonts Lists Feed RSS Advertising Contact Me

Wednesday, December 31, 2008

Super elastic effect to design high impact web menu

19 comments
Save to delicious 0 hits

This tutorial explais how to design an high impact elastic effect to make original web menu using some lines of Javascript code and MooTools framework. The effect is simple to develope and reuse in your web projects changing only HTML code and CSS. Take a look!

The effect I want to realize is the following. I have a "layer cloud" with some layer overlapped to the others. On "mouse over" the select layer goes down with a nice animation effect and when you release the element this goes up with an elastic effect:




Take a look at this live preview to see this script in action.

Download source code Live Preview


1. HTML code
Create a layer which contains all elements in the "cloud" (in this case I used DIV elements):

<div id="container">
<div id="contact">This is the layer about me.</div>
<div id="about">Contact me? <a href="mailto:myemail@email.com">My Email</a></div>
<div id="profile">This is my <a href="http://woork.blogspot.com">website</a></div>
</div>


2. CSS Code
Use CSS to stylize previous elements how you prefer. In this tutorial I used this CSS code:

#about {
width: 200px;
padding: 8px;
background: #DEDEDE;
color: #333;
position: absolute;
z-index: 1;
left: 31px;
top: 66px;
border:solid 4px #CCC;
}

#about {
width: 200px;
padding: 8px;
background: #DEDEDE;
color: #333;
position: absolute;
z-index: 1;
left: 80px;
top: 37px;
border:solid 4px #CCC;
}
...

The result is something like this, a "layer cloud" with some layer overlapped to others:




You can add other overlapped layers simply adding new <div> elements in step (1) with the related CSS stlye in step 2. To overlap layer I use CSS properties "position:absolute" and "z-index" for each element.


3. JavaScript code
In order to obtain our elastic effect I used MooTools framework and some lines of Js code.
No fear... it's very simple! In the <head> tag of the page add a link to MooTools:

<script type="text/javascript" src="mootools.svn.js"> </script>


Now, copy and paste this code below the previous line of code in the <head> tag of the page (if you prefer you can also copy this code in a separated .js file and import it in your page):

<script type="text/javascript">
window.addEvent('domready', function(){
var zindex = 2;
$('#container div').each(function(item){
var o = item.id
var fx = new Fx.Style(o, 'margin-top', {
duration: 1000,
transition: Fx.Transitions.Back.easeInOut,
wait: true
});
item.addEvents({
'mouseenter' : function(e){
fx.stop()
fx.start(0,100);
zindex = zindex + 1;
$(o).setStyle('z-index', zindex)
},
'mouseleave' : function(e){
fx.stop()
fx.start(0);
zindex = zindex - 1;
$(o).setStyle('z-index', zindex)
}
});
})
});
</script>

In this code I used a MooTools basic knowledge. In the past week I already dedicated several lessons about that. I suggest you to take a look at these post:


Download source code Live Preview

It's all! Do you have some suggest? Add a comment!

Sponsored Links
Share this post
Share on Facebook
Share on Twitter
Share on StumbleUpon
Share on Delicious
Share on Reddit
Share on Digg
Share on DesignFloat
Share on Technorati
Feeds RSS Subscribe to Feeds RSS
Comments
19 comments
Do you have any suggestions? Add your comment. Please don't spam!
Subscribe to my feeds | Subscribe comments feeds
Konny said...

Hey man... another great post. You are the best! Haooy new year!!!!

Wesley said...

Nice and clean code, but I'm not really sure what the use of this particular effect is :) I guess it's a proof of concept since putting this online would only aggrevate your visitors (trying to click a link, etc).

jcargoo said...

Hi,
I find it nice but I don't see the point here! What is clearly the purpose?
Thanks to clarify please
Regards,

Spencer Barfuss said...

Hey Antonio, not exactly sure what this cloud effect is supposed to do. It doesn't seem to be working very well, and might be a bit frustrating for the user.

Antonio said...

Guys... yes this is a proposal. I suggest to use it with horizontal elastic effect (change margin-top -> margin-left) and with a link (with css display property set block) instead of div.

Vaibhav Gupta said...

Thank you.

Very nice and good job.

Taimoor-Blogger said...

Nice Tut Antonio.Happy New Year Still Waiting For Template.

taylan said...

Great codes. But i cant catch any link!

www.MonjurulHoque.com said...

Thanks BOSS...
& Happy New Year....

Naeem said...

very good tutorial antonio.

http://naeemnur.bloggspot.com

zihotki said...

Hi,
In my opinion this menu is awful - in my FF elements are jumping all of the time and I can't catch any link at all, in Chrome it works more good, but I can't catch links too. In IE 7 it is similar to Chrome but has few another bugs. And I can't see what is on the menu items that are hovered by other items. It is very unusable. I didn't recommend to use it on live sites :(.
Thank you

tips dan trik blogger said...

thanls for the info antonio! u the best!

Joel Laumans said...

Good tutorial, but this is totally pointless to add on your site. Clicking the links in the "live preview" was impossible.

web site design said...

u r blog Is very nice

Ralph said...

Thank you for your great idea and work. Ralph

Anonymous said...

wtf? please show an example where this would have a point

KleinM said...

this is nice, but it has a problem on mac - firefox. Will take a look later one at home to see how it can be fixed, but i looked at it in Safari and the effect is sweet.

Anonymous said...

This would be great for a portfolio website to show off images and create a fun effect.

strony internetowe said...

very nice code, and post:) great.

About Me

I am Antonio Lupetti, Engineer, Pro Blogger, Mac user, Web addicted. Rome, IT.
Feeds RSS Contact Me

SubscribeLatest posts

SubscribeHot Links

Subscribe Design News

Ecoki Eco Green Product Reviews
Apple Reviews and News
CSSRockstars - You Design, We Code. Your PSD to HTML/CSS for just $149