Sliding Top Menu With jQuery
Sliding menus are very effective in areas where we have limited space .
This is a sliding top menu built with jQuery which can be fired through the open & close buttons or with any tag with the related class name.
You can also use it as an info box, login area & more.
Click here to see the final working demo of this jQuery sliding menu.
It presents the menu when closed like this:
![]()
And when opened:

Click here to see the final working demo of this jQuery sliding menu.
Step 1 - HTML:
<div id="sliderWrap">
<div id="openCloseIdentifier"></div>
<div id="slider">
<div id="sliderContent">
Isn’t this nice?
</div>
<div id="openCloseWrap">
<a href="#" class="topMenuAction" id="topMenuImage">
<img src="open.png" alt="open" />
</a>
</div>
</div>
</div>
Step 2 - CSS:
<style type="text/css">
body {
margin: 0;
font-size:16px;
color: #000000;
font-family:Arial, Helvetica, sans-serif;
}
#sliderWrap {
margin: 0 auto;
width: 300px;
}
#slider {
position: absolute;
background-image:url(slider.png);
background-repeat:no-repeat;
background-position: bottom;
width: 300px;
height: 159px;
margin-top: -141px;
}
#slider img {
border: 0;
}
#sliderContent {
margin: 50px 0 0 50px;
position: absolute;
text-align:center;
background-color:#FFFFCC;
color:#333333;
font-weight:bold;
padding: 10px;
}
#header {
margin: 0 auto;
width: 600px;
background-color: #F0F0F0;
height: 200px;
padding: 10px;
}
#openCloseWrap {
position:absolute;
margin: 143px 0 0 120px;
font-size:12px;
font-weight:bold;
}
</style>
With the CSS file there are few major points:
- #slider has to be positioned absolutely, so it can overlay the other content.
- #slider has a negative top-margin which hides it.
- #sliderContent is positioned absolutely to not to crack the open/close buttons
- #openCloseWrap holding the buttons are positioned absolutely too.
Step 3 - jQuery / JavaScript:
<script type="text/javascript">
$(document).ready(function() {
$(".topMenuAction").click( function() {
if ($("#openCloseIdentifier").is(":hidden")) {
$("#slider").animate({
marginTop: "-141px"
}, 500 );
$("#topMenuImage").html(’<img src="open.png"/>’);
$("#openCloseIdentifier").show();
} else {
$("#slider").animate({
marginTop: "0px"
}, 500 );
$("#topMenuImage").html(’<img src="close.png"/>’);
$("#openCloseIdentifier").hide();
}
});
});
</script>
The main trick is changing the top margin of #slider and update the open / close images.
We have an empty element named openCloseIdentifier which shows us whether the menu is open or closed. We simply hide it when the menu is open and show when it is closed.
Then all we do is:
if openCloseIdentifier = hidden then close the menu or if openCloseIdentifier = visible then open the menu.
Sliding effect can be fastened by changing the 500 value in JavaScript to a smaller number or else.
P.S. Down & up arrow icons are from the Crystal Clear icon set.
Compatibility: All Major Browsers
Demo: http://www.webresourcesdepot.com/wp-content/uploads/...
Download: http://www.webresourcesdepot.com/wp-content/uploads/...
- Tags:
jQuery
- Filed under: Extras, Goodies, License Free, Menu & Navigation, Tutorials





33 Responses for "Sliding Top Menu With jQuery"
it is nice
This is a lot like the jQuery search box that’s documented at the Lullabot website: http://www.lullabot.com/articles/bitchin_search_box
great .
but it can be easer if you use slideToggle()
http://docs.jquery.com/Effects/slideToggle
Thanks, very nice.
[...] jQuery ile sürgülü üst menü. Bağlantı [...]
[...] Web Resources Depot | Sliding Top Menu With jQuery Categoria Diseño, JavaScript, Programacion, WEB2.0, jQuery [...]
@Christefane,
Just checked it aand it is a nice implemantation too.
@saeed,
You’re right, with slideToggle() I could have done it without the openCloseIdentifier which already what the toggle is :). Missed that. Thanks
That looks great, thanks for code and tutorial!
Nice job with the tutorial! Two things you might want to consider with the CSS:
1. Use
position: fixedfor #sliderWrap and then serveposition: absoluteto IE6 through an IE6-only stylesheet (using conditional comment) or with the “* html” hack. That way the top menu will always be visible to the user if he or she is using anything other than IE6.2. If other elements on the page have position (other than static), you might need to add a z-index property to #sliderWrap
Keep up the great work with these tutorials!
This is a really cool jQuery menu. Thanks mate for sharing this.
[...] | Menu deslizante con jQuery Surgio en | Sliding Top Menu With jQuery Pertenece a Ajax, Ajaxman, Javascript, Jquery, Programacion, Recursos [...]
This reminds me of the tutorial on web designer wall.
http://www.webdesignerwall.com/tutorials/jquery-tutorials-for-designers/
Nice little app there… does it play nicely with the major browsers out there?
[...] a strain on users browser. Great animation effects can be achieved using jQuery; for instance this tutorial tells you how to create a sliding menu using jQuery. Technorati Tags: jquery, sliding [...]
@Travis,
Yes, looks similar with a difference, this one adjusts the margin of the menu rather than toggling. Result is the same.
@Chris,
I tested this with IE6, IE7, FF2, Opera & Safari at Windows and all are ok. For IE6 if you’ll use PNG you need a IE PNG fix hack.
Nice. But it just feels like this is crying to be draggable as well.
Cute, you might want to update this for when JavaScript is turned off.
p.s. nice website
Nice:)
yes very very nice.
The ‘Open it!’ link could be slightly bigger!
#openCloseWrap a {padding:0 10px}
Thanks for the tutorial
[...] wirklich vielfältig einsetzbares Widget ist das “Sliding Top Menu“. Das Widget ist als jQuery Plugin entwickelt und lässt sich in wenigen Schritten in die [...]
Far out,
Thanks very much for the code!
Hy, nice tool!
Instead of open the tab by clicking i want to open that thing by mouseover and closed again when leaving the slider div.
is that possible? i tried to write onmouseover instead of click, but didn´t work - i´m pritty bad in javascript
can we work that out?
[...] Menu - Heute, 11:34 Hy, auf der Suche nach einem Menu bin ich auf das hier gesto
[...] Sliding Menu is similar to the slider side bar. [...]
Looks great, can it be placed any where on a page or does it have to be at the top?
@jj,
Yes you can place it anywhere. You can even make it slide from left to right or else by playing with the margins..
Nice
This is a cool tutorial, I used it and it worked at the first time.. very good!
hi is there a way to change the words “openit!” and “closeit! to something else?
thx
@bluejay00234,
That part is an image and you can simply modify it.
Nice work. Is it possible to move the menu to the bottom of the screen?
Valid XHTML | Valid CSS
Popular Posts