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




















56 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?
This is excellent! Nice work
I am curious though…I have a flash movie I need in the header ID, but other than in Safari it floats over everything in all other browsers.
Any Thoughts?
Thanks!
its simple and very usefull…thanks for your codings…
hey is it possible to have it working in the complete opposite direction from say the bottom of a fixed div or table so that it slides from the bottom up?
Thanks in advance!
that it slides from the bottom up?
This is quite a cool slider.
Quite nice, it inspired me a lot.
Nice Tutorials, Thanks.
Great work
Have anyone tried the slider while the jquery pngFix? I’m having problem using both at the same time.
How can i make it Auto open at the start then they have to push close?
@Adam,
Without adding or removing anything, add these after: $(document).ready(function() {
$(”#slider”).animate({
’);
marginTop: “-141px”
}, 500 );
$(”#topMenuImage”).html(’
$(”#openCloseIdentifier”).show();
I believe this must do the trick.
very nice !!! but how to open top menu first ?
@xlife,
Have you tried the code above?
thanks
i’m tried
this code after
————————
$(document).ready(function() {
—————————
$(”#slider”).animate({
marginTop: “0px”
}, 500 );
$(”#topMenuImage”).html(”);
$(”#openCloseIdentifier”).hide();
———————————————
question +
how to upgrade for jquery-1.3.2.min
thanks
@xlife,
As far as I know, the functions used haven’t changed in jQuery 1.3.2. It doesn’t work with jQuery 1.3.2?
Hi
This Works perfectly fine but wanted to know if I can do it 100% instead of fixing the height to hieight
$(”.topMenuAction”).click(function() {
if ($(”#openCloseIdentifier”).is(”:hidden”)) {
$(”#sliderWrap”).animate({
marginTop: “-659px”
}, 500);
instead of -659px I need it to adjust to the content . As My content would be comming dynamically
please help me out
@Umut M.
when i’am close this tab i can’t open it again
// jquery 1.3.2
problem with show(); ?
@padma,
I would suggest that you get the height automatically with: http://docs.jquery.com/CSS/height function which will probably help you.
@xlife,
I truly can’t see a reason as tab open/close are both done with the animate function which still exists. Sorry for not being able to help there. Please update us if you get the reason.
@Umut M & @xlife
I cant get it working at all with jQuery 1.3.2,
Any help with a fix would be much apprecitated.
Many thanks
No, it is not working with 1.3.2
Taking the downloaded demo and replacing the link to jquery with a link to the current version stops the demo from functioning.
bug 1.3.2
jquery-1.3.2.min.js
fine
hidden=function
hidden=function(T){return T.offsetWidth===0||T.offsetHeight===0}
to
hidden=function(T){return T.offsetWidth===0&&T.offsetHeight===0}
—-
http://dev.jquery.com/ticket/4374
http://dev.jquery.com/changeset/6282
For jquery 1.3.2 bug, add
#openCloseIdentifier
{
height: 1px;
}
on css
it’s because newest version of jquery consider as hidden elements without height or width
Thank you.
Fix coded.
hi ,
its really nice , but i want on right side at same position( i mean in center ) how i can do that
wht sort of changes i have to do ?