From our sponsor: Ready to show your plugin skills? Enter the Penpot Plugins Contest (Nov 15-Dec 15) to win cash prizes!
Today I want to show you how to create an amazing slide out menu or navigation for your website. The navigation will be almost hidden – the items only slide out when the user hovers over the area next to them. This gives a beautiful effect and using this technique can spare you some space on your website. The items will be semi-transparent which means that content under them will not be completely hidden.
The icons that we will be using are from the Colorful Sticker Icon Sets 1, 2, 3 and 4 by DryIcons. (It is not allowed to redistribute them under the free license, so I cannot include them in ZIP file of this tutorial.)
Ok, let’s get to work.
Tiny break: 📬 Want to stay up to date with frontend and trends in web design? Subscribe and get our Collective newsletter twice a tweek.
1. The HTML Structure
The only thing we will need for the navigation is a simple unordered list with links inside of the list elements:
<ul id="navigation"> <li class="home"><a title="Home"></a></li> <li class="about"><a title="About"></a></li> <li class="search"><a title="Search"></a></li> <li class="photos"><a title="Photos"></a></li> <li class="rssfeed"><a title="Rss Feed"></a></li> <li class="podcasts"><a title="Podcasts"></a></li> <li class="contact"><a title="Contact"></a></li> </ul>
The list is getting an ID because we want to refer to it later in the JavaScript. With jQuery, we will make the link items slide out whenever we hover over the li elements of the list.
2. The CSS
First, we define the CSS properties for the list:
ul#navigation { position: fixed; margin: 0px; padding: 0px; top: 10px; left: 0px; list-style: none; z-index:9999; }
The navigation should always be accessible for the user, even if he scrolls down the page. So, the position should be fixed. Margin and padding are explicitly set to 0, since the unordered list has default values for them. The navigation should also be on top of all other elements on the page. That’s why we set the z-index very high.
Now, let’s look at the list element properties:
ul#navigation li { width: 100px; }
For the links in the list elements, we define the following CSS properties:
ul#navigation li a { display: block; margin-left: -85px; width: 100px; height: 70px; background-color:#CFCFCF; background-repeat:no-repeat; background-position:center center; border:1px solid #AFAFAF; }
The margin-left is set to a negative value because we want to hide most of the icon and only reveal it when we hover over the list items. Basically, we are pushing the link element to the left, outside of the visual area of the page:
In the JavaScript part we will define a function that makes the elements slide out. But let’s first add some rounded borders to them (they don’t work in Internet Explorer, though):
ul#navigation li a { display: block; margin-left: -85px; width: 100px; height: 70px; background-color:#CFCFCF; background-repeat:no-repeat; background-position:center center; border:1px solid #AFAFAF; -moz-border-radius:0px 10px 10px 0px; -webkit-border-bottom-right-radius: 10px; -webkit-border-top-right-radius: 10px; -khtml-border-bottom-right-radius: 10px; -khtml-border-top-right-radius: 10px; }
To make them really neat, we add some opacity, so that the content underneath is visible:
ul#navigation li a { display: block; margin-left: -85px; width: 100px; height: 70px; background-color:#CFCFCF; background-repeat:no-repeat; background-position:center center; border:1px solid #AFAFAF; -moz-border-radius:0px 10px 10px 0px; -webkit-border-bottom-right-radius: 10px; -webkit-border-top-right-radius: 10px; -khtml-border-bottom-right-radius: 10px; -khtml-border-top-right-radius: 10px; opacity: 0.6; filter:progid:DXImageTransform.Microsoft.Alpha(opacity=60); }
The last filter property will make this work for Internet Explorer as well.
These were the common properties of all the link elements in the list. Now we will define the background image for the links in the specific list items:
ul#navigation .home a{ background-image: url(../images/home.png); } ul#navigation .about a { background-image: url(../images/id_card.png); } ul#navigation .search a { background-image: url(../images/search.png); } ul#navigation .podcasts a { background-image: url(../images/ipod.png); } ul#navigation .rssfeed a { background-image: url(../images/rss.png); } ul#navigation .photos a { background-image: url(../images/camera.png); } ul#navigation .contact a { background-image: url(../images/mail.png); }
And that was the CSS part. Now, let’s take a look at the few lines of JavaScript that will give some life to the navigation.
The JavaScript
Using jQuery, we will make the icons appear whenever we hover over one of the list items. Remember, the list item itself is 100 pixel wide, only the link element is being pushed outside of the page to the left, so that it is not visible.
We define the following function (before the end of the body tag) that get’s executed whenever we hover over a li:
$(function() { $('#navigation > li').hover( function () { $('a',$(this)).stop().animate({'marginLeft':'-2px'},200); }, function () { $('a',$(this)).stop().animate({'marginLeft':'-85px'},200); } ); });
So, when hovering, we want the specific link element to get a left margin of -2 pixels, and that nicely animated, and not too slow (200 milliseconds). Moving the mouse out shall put the link element back to it’s old position (-85 pixels). The stop() function “stops all the currently running animations on all the specified elements” which gives the beautiful effect when, for example, hovering over all elements very quickly.
What would be really nice now, is to make the user aware that there is such an amazing navigation on your web page. Like it is now, the user will merely see some grey borders sticking out from the left side of the page. What could be better for showing the menu than actually showing the navigation shortly when the page loads. So, here we go.
So, we will initially let the navigation be visible. For that we change the left margin of the link elements:
ul#navigation li a { display: block; margin-left: -2px; width: 100px; height: 70px; background-color:#CFCFCF; background-repeat:no-repeat; background-position:center center; border:1px solid #AFAFAF; -moz-border-radius:0px 10px 10px 0px; -webkit-border-bottom-right-radius: 10px; -webkit-border-top-right-radius: 10px; -khtml-border-bottom-right-radius: 10px; -khtml-border-top-right-radius: 10px; opacity: 0.6; filter:progid:DXImageTransform.Microsoft.Alpha(opacity=60); }
And we add the following line at the beginning of the JavaScript function:
$(function() { $('#navigation a').stop().animate({'marginLeft':'-85px'},1000); $('#navigation > li').hover( function () { $('a',$(this)).stop().animate({'marginLeft':'-2px'},200); }, function () { $('a',$(this)).stop().animate({'marginLeft':'-85px'},200); } ); });
With that line we defined that it should take 1 second to give a left margin of -85 pixels to all the link elements in the list. Through the margin that we set we will show the navigation to the user and with the JavaScript we will then hide it.
And that’s it!
If you are a shadow-freak (like me), you can also add these lines to the CSS of the link element:
ul#navigation li a { display: block; margin-left: -2px; width: 100px; height: 70px; background-color:#CFCFCF; background-repeat:no-repeat; background-position:center center; border:1px solid #AFAFAF; -moz-border-radius:0px 10px 10px 0px; -webkit-border-bottom-right-radius: 10px; -webkit-border-top-right-radius: 10px; -khtml-border-bottom-right-radius: 10px; -khtml-border-top-right-radius: 10px; -moz-box-shadow: 0px 4px 3px #000; -webkit-box-shadow: 0px 4px 3px #000; }
Adding the box shadow and removing opacity, will give the navigation items a 3D look. Leaving the opacity makes them look cool, too, try it out and enjoy!
Note: Check out an alternative version of this tutorial here
i am having trouble getting my own icons to show up on the sliders. ive inserted the correct .png’s into the code, but they will not show up. what am i doing wrong?
Nice very nice and very beautiful menu. I love this stuff
This is amazing, i recently ran into a minor copyright issue while using a jquery plugin. I was wondering what copyright credits do i have to use to use your slide out navigation
How to put a text in it?
Thanks…..great tutorials…….
great its a very professional slide out navigations, the icons and the style are very nice, im going to add it to my website http://www.ajaxshake.com , thanks Mary Lou
Great collection…………………………thanks 🙂
This tutorial taught me well, thank you 🙂
This is a great tutorial – we’ve featured it on our Top 6 jQuery & CSS Navigation Tutorials here: http://www.siliconbeachtraining.co.uk/blog/6-css-jquery-navigation-bar-tutorials/
I like this ! Very nice. I got one question about this solution. I don’t want the “optical slide” by every page load.
How can i remove this option ? It must shown once instead of every load.
Really beautiful slide out navigation tutorial. Thanks for publish..:)
Hi !!! How are you?
I can not switch sides from left to right!
Can anyone help me?
I just need to change the side to the right!
Thanks !!!
Karian Silva
Hello, congratulations on your website, sorry I wanted to know how to do that instead of the menu to be lateral is in the top, please I’ve tried it and can not.
I love this nav but I cannot for the life of me get it to work with another jquery script. What I want to do is use this nav on the left and upon clicking on a thumb, activate the window on the right. The page:
http://www.scarsarebeautifulcampaign.com/archived/storiesII.html
So if you clicked on the second thumb in the nav, the content in the right window would transition via the slider jquery (in this instance it’s jcarousel, a second choice). I’ve tried three diff. sliders and none work. Can anyone help?
very good
best ideas
Thanks alot
I want to do is use this nav on the left and upon clicking on a thumb
To make them really neat, we add some opacity, so that the content underneath is visible.
Hello its nice really but if i want same Effect with right Side means i want Right navigation with my Site.
Great Work and to top it very well explained..
my question is, how can I dynamically change the number of navigation buttons?
say initially the webpage started out with 7 buttons and depending upon user choice selected, I want to provide 10 navigation buttons, so i need to refresh the navigation bar.. how can I do that? thank you
I wanted to know how to do that instead of the menu to be lateral is in the top, please I’ve tried it and can not.
thanx a lot !!
Hi, Mary Lou. Is there a way to add a button to the navigation so the user can partially “hide” it?
hey, what sketchy font is that you used?
So, the position should be fixed. Margin and padding are explicitly set to 0, since the unordered list has default values for them.
This tutorial is good and easy to understand…
Thanks…
Hola, esta muy bien este tutorial, pero kisiera pasar el menú al lado izquierdo, como lo paso?? alguien sabe?
I want to provide 10 navigation buttons, so i need to refresh the navigation bar.. how can I do that? thank you
The only thing I wanted to know is how to change the rollover effect so that the boxes that I hover on slides to the left instead of the right.
The navigation should always be accessible for the user, even if he scrolls down the page. So, the position should be fixed. Margin and padding are explicitly set to 0, since the unordered list has default values for them.
Wow, this is awesome!
Is there anyway I can place the menus on the right side of the screen?
I have one question, there are any way to fix one of the tabs with any animation.
can you make and a top/down/left site version ?
or how to make this one to stay on the right side of the page and popout to left ?
Excellent tutorial, thank you very much. Can you please explain (or point me to a resource) how to incorporate this type of navigation into a SharePoint environment/page? Thank you in advance.
Nice Work.
Thanks For Sharing It
very nice, i need its navi
Superb tutorial, easy to implement, and looks stunning.
For those who’d like to implement it on the right side:
$(‘#navigation1 > li’).hover(
function () {
$(‘a’,$(this)).stop().animate({‘marginLeft’:’-120px’},300);
},
function () {
$(‘a’,$(this)).stop().animate({‘marginLeft’:’2px’},600);
}
);
});
and
ul#navigation {
right: 0px;
ul#navigation li a {
margin-left: 2px;
Nice and simple. But very effective to capture eye balls and minimise space.
Will be using it in my future projects. Thanks.
Hello, congratulations on your website, sorry I wanted to know how to do that instead of the menu to be lateral is in the top, please I’ve tried it and can not.
I will definetly use this!! Very nice effect !
Thanks a lot
Love it! Nice and clean.
I´m enjoying every site here. One of the best tutorials ever. Thanks a lot.
interesting and neat technique, thanks mate
Hy Mary,
realy cool slide menu!
I use it on my site.
thx for sharing!
This gives a beautiful effect and using this technique can spare you some space on your website
Amazing tutorial!
Thanks a lot!
The list is getting an ID because we want to refer to it later in the JavaScript. With jQuery, we will make the link items slide out whenever we hover over the li elements of the list. thanx
Hi i want to know how i can make that the button stay “selected” when the user make a click on it… thanks in advance!!
gr8 explaination, using a lot of what you explained in my project 😉
i m happy you do great job