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
- 112 Comments
Related Posts


















112 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,
. Missed that. Thanks
You’re right, with slideToggle() I could have done it without the openCloseIdentifier which already what the toggle is
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 ?
hi, thanks for the code, but how to make the slider for multiple button, so in one page there’s more than 1 slider. where did i must customize?
This was asked but i’m not sure answered. I’d like to use this for each navigation item on a site i’m building,but i need it to slide down on mouseover and slide back up onmouseout/when focus on the menu is moved. Is this possible? I assume i’d just setup a unique div for each one – so i can have multiple sliders on the same page?
Thank you.
Thanks. Look great n cool.
Wow… nice script…
Thank You very much… for great script…
Hi guys. u say..”isn’t this nice?.” Yup. that really nice. Great scripts impression. Cool. Thanks 4 the script. Good work
Hi, I’d like to add a shoutbox into this but it shows below the open/close tab. I can’t seem to be able to adjust the height to keep the contents of the iframe hidden?
P.S. Newbie here, just trying to learn some new stuff. :0) Thanks!
Hi guys..I came here for the second time. I also thinking..the example u show is by click. How about it’s open just on mouse over?
Hi guys
I have just been preparing a new flash video for my homepage.
I want to use this sliding top menu like a screen that is pulled down, and then have the video play on the screen after it slides. Any ideas how I could connect “Open it!” with the play button for the video, so it would start to play automatically after it slides down?
Sorry if this is a crazy idea, but it would be awesome!
@Web Suunnittelu,
That sounds like a nice idea.
It is very easy to do, however you need to use a video player that can be controlled via JavaScript (like Flowplayer). So you can add the “video-start” function just after the line that slides the content.
This is the nice one
Thanks Dear
How can I transform the panel to slide down/up on mouseover/mouseout ?????
could you explain how to change the margins to get it moving horizontally please?
Thanks for the tutorial by the way, i got it working straight away. rad
Such nice !!!
cliche tip: adding a z-index:255 if the close button falls under e.g. a google ad.
coool thanks very much
Earlier it was said that this slider can appear anywhere on the page. I have it placed under a table with a background image. How can I have the content hidden behind the table though and still be clickable? I have modified the z-index of both and have not found a solution.
^Nevermind… don’t know what I was doing wrong, but works now.
Nice, seems like a lot of unnecessary markup to me though.
@Web Suunnittelu
U can use jw-player and use its API, very easy.
Nice script btw
Nice script,
This seems to work ok with most browsers but with with IE6 using ie7.js fix to fix pngs the it stops working? Any ideas why or what pngfix would you recommend?
It’s nice, excellent work,
and main thing is easy to use,
Thanks.
excellent jquery work but my problem is that i can’t increase a menu height, so give a solution. I can tired the this problem. please give a solution.
@raj,
You’ll need to update the height settings in CSS and also the marginTop value in JS.
@Chris,
Didn’t check with any PNG fix, IE7.js is also my favorite. Sorry, no suggestions that I tested.
Is there a way to put multiple tabs acroos the top of the page that open seperate panels
@Mary Zibro,
Yes sure, you need to duplicate the JS & HTML codes. And also, change the ids,classes.
Hi,
I am having a problem with this script where I have a wrapper element, then I have the drop down box floated to the right but my wrapper wont extend underneath the drop down menu, it just moves down onto another line ?
Any Help ?
wow, I tested it, and it work this is the first time to use a jquery
thanks
Hi. Very nice indeed. What happen if I like to reserve the menu to the bottom of the page? I tried using positioning absolute I manage to get the content to slice up but not the button. Any tips?
you was right.
Hey,
Just a quick issue, because the menu is dropping down a navigation bar to parts of the first page. When i click close it takes me right back up to the top of the page. Is there a way to close it without the page going right back up to the top?
How about an outline:none on the anchor tag, its annoying to look at after the first time you click it.
How to make it slide from left side to right side on the left Navigation?
What changes i need to make?
Please help.
Is it only working on div tag?
Because when i use tr and td tag, it doesn’t work.
Thanks a lot for sharing the article. Was looking for a horizontal instead of vertical menu. But this article anyways solved my problem.
Is it working also for browser that no has Javascript activated ?
@yusuf,
Nope. It doesn’t.
Since I can change the manu to a wings to the right -> interesaria a lot of power extract for example the respuesto.
Thank you very much in advance
Its nice. thanks for sharing.
Is there an answer to positioning and having it come up instead of down?
Useful information..thx Thank You for having us
excellent information, thank you thanks for the inspiration!
Great looking solution. I’ve ALMOST completed it, just can’t get it in hidden state when the page loads. The content div is visible. How can I resolve this? Any clues? Look at http://www.sunacnetreatment.com
Thanks,
Chris
Hello,
this doesn’t seem to work with jquery-1.3.2.min.js, you can view my example here
http://www.justinblayney.com/new/topslider.php
if i switch it back to 1.2.6 it works, but my other scripts wont…
Great Tutorial. I have used on my site and works perfect. Check out ChillTip.
http://www.chillwebdesigns.co.uk/chilltip.html
Thanks for this awesome menu, very unique tutorial,
thanks…
Hi,
this is an awesome method for the drop down, however is it possible to Z-index it so that it comes from behind a different Div, i’ve been trying to achieve it butwith little success.
Thanks
Hi , This is good work from your side.
But i need some more asist from you. I place it on header div the scroller want to run behind header. i use Z-index but inside content link are in active.
Umut, it would be good to fix CSS bug for jquery 1.3.2 in the download code itself. Thanks for the code though.
How to create multiple sliding menus in a page and have one of them close when the other one opens and all that? I have tried this but not successful!!! HELP !!!
Trying to have it open on landing. Tried:
“…
Without adding or removing anything, add these after: $(document).ready(function() {
$(“#slider”).animate({
marginTop: “-141px”
}, 500 );
$(“#topMenuImage”).html(’’);
$(“#openCloseIdentifier”).show();
…”
but there is a syntax problem and it won’t work. Could somebody please tell me “add after” what?
good good very good slide
Damn. Doesn’t work with latest versions of jQuery
It does work well with 1.2.6 though at least.
Sorry, I take that back, it just doesn’t work with no conflict mode set on.
The following code fixes that problem:
var $ = jQuery;
I saw this nice menu and implemented it. It works great and looks great for my purpose.
But when I see the final result I realize that I probably need a dim out effect a la lightbox to go with this.
I’m only a novice scripter and dont think I can make this happen on my own. Anyone here that could sink their teeth into this idea?
I surprise myself.
I made the dim out work using the code found here:
http://buildinternet.com/2009/08/lights-out-dimmingcovering-background-content-with-jquery/
Basically just add their class “alert” to the class “topMenuAction” like this
a href=”#” class=”topMenuAction alert”
Also add their close for the dim out to this script
$(“#openCloseIdentifier”).show();
$(“#dim”).fadeOut();
Finally add the dim div and the ccs
hai good work
i need one more thing on that hide div if user click out side ant where. can any one help me.