Just about every website uses the regular navigation concepts we're all used to. After awhile this can get pretty boring, especially for designers who thrive on creativity. While mimicking the OS X dock and stacks isn't new, it's certainly not common.
A few days ago, Jeffrey posted about a potential "outside the box" competition on ThemeForest to encourage authors to put on their creativity hats and design usable templates with "outside the box" creative designs. In this tutorial I'll cover a few ways to do just that with OS X style docks and stacks navigation.
Sources and Credits
Before we get started, I want to give a shout out to a couple guys who came to the rescue when they heard my call for help on Twitter. Steve updated the stacks script by Harley from using jQuery 1.2.6 to use the current 1.3.2 release and Rey Bango from the jQuery team helped me fix a bug. They both jumped to the task within a couple minutes of my cry for help via Twitter. Thanks a ton guys! *Round of applause* :-D
Original Sources
- "Adding to Our Leopard Desktop with jQuery" by Harley via Net.tutsplus.com
- Interface: Fisheye Menu
- jqDock v1.2
- Example template (Internet Encyclopedia) by Luka Cvrk
Quick Notes
These scripts rely on jQuery 1.3.2. The examples shown are compatible with all major browsers including IE6 and are easy to ensure graceful degrading if JavaScript is off or disabled.
jQuery OS X Dock #1 (Horizontal)
The first dock we'll build uses the jQuery Fisheye Menu plugin mentioned above. It's pretty lightweight (~7kb with dependencies) but the main reason I wanted to use this one was because it's incredibly smooth, no stuttering. View Demo.
As you can see in the demo, it's incredibly smooth and responsive. The downside is that you can't use fixed positioning with it if the page needs to scroll as it will break. If you don't need it fixed within the browser window then it works great.
This is a great example of "outside the box" concepts in websites and provides an interactive and fun interface.
Required files (I've combined the Fisheye plugin and iutil.js in the demo files).
- jQuery 1.3.2
- Interface: Fisheye Menu plugin
- Interface: iutil.js (dependency)
The HTML
We'll wrap our images and titles in links and place them within a containing div. Then we'll wrap it all in another containing div for it to function properly.
Notice that I've placed the titles in span tags so we can style them as well as allow the plugin to hide/show them as necessary.
The CSS
With CSS we'll position the dock where we want it on the page. We can't use fixed positioning with this plugin or it won't function properly.
.dock-container { position: relative; top: -8px; height: 50px; padding-left: 20px; }
a.dock-item { display: block; width: 50px; position: absolute; bottom: 0; text-align: center; text-decoration: none; color: #333; }
.dock-item span { display: none; padding-left: 20px; }
.dock-item img { border: 0; margin: 5px 10px 0px; width: 100%; }
I've also placed a little extra CSS in the head of the page below the CSS included above. I wrapped it in noscript tags in case a visitor doesn't have JavaScript enabled or available, it will still be a usable navigation. I should point out that this will not validate because the noscript tag isn't valid in the head section, even though it works in all the current browsers. ;-)
#dock { top: -32px; }
a.dock-item { position: relative; float: left; margin-right: 10px; }
.dock-item span { display: block; }
The JavaScript
We'll bring in our JavaScript files now starting with jQuery 1.3.2. The fisheye-iutil.min.js file is the combination of the Fisheye plugin and its dependent iutil.js file. We'll create the last file and put our JavaScript necessary to initialize the dock in it.
Now we'll initialize the dock once the page loads. You can use several plugin options to customize the dock as you need for positioning and functionality. You can view the documentation by visiting the site listed under sources for the Fisheye plugin.
$(function () {
// Dock initialize
$('#dock').Fisheye(
{
maxWidth: 30,
items: 'a',
itemsText: 'span',
container: '.dock-container',
itemWidth: 50,
proximity: 60,
alignment : 'left',
valign: 'bottom',
halign : 'center'
}
);
});
That's all there is to it! :-D
jQuery OS X Dock #2 (Vertical)
The horizontal dock was easy and definitely a neat idea to use on websites. They're probably the most common type used across the web currently so let's try something different. We could get a little more "outside the box" if we did a vertical dock navigation.
This dock relies on the jqDock jQuery plugin. It's approximately 10kb in size, so it's a few kb larger than the previous version but that's not much. The disadvantage to this plugin is that it's not quite as smooth as the Fisheye plugin dock, although it's still very fluid and certainly usable. This plugin also doesn't have issues with fixed positioning. View Demo.
The HTML
We'll put our images in an unordered list and wrap them in links. As with the last plugin, we'll wrap everything within a containing div. When we initialize the plugin we'll use the "ul" here.
You'll notice on this dock we don't have titles wrapped in span tags. Instead, this plugin will look at the "title" tag set for each image and create the titles that way (if enabled in the plugin options). This makes the markup a little simpler but it also makes the titles a little less customizable.
The CSS
We position the dock on the left side (can be either side) using fixed positioning. We'll give it a little space between itself and the top of the browser window for aesthetics and so the icons don't disappear when enlarged.
#dockContainer { position: fixed; top: 60px; left: 6px; }
#jqDock { position: relative; bottom: 48px; }
.jqDockLabel { background: #333; color: #fff; padding: 3px 10px; -webkit-border-radius: 10px; -moz-border-radius: 10px; }
To style the titles we can use the ".jqDockLabel" class. We also won't need to include any extra styles for it to still be usable with JavaScript disabled. It may not be very pretty but it's functional.
The JavaScript
We'll bring in the jQuery library just like the previous dock as well as the plugin.
We initialize the dock and set a few options to customize it. You can read the documentation on these settings by visiting the site listed under sources at the beginning of the tutorial for jqDock. What I want to point out here though is the duration option. This is the time for magnification animation in milliseconds. It's nice to be able to change the duration speed but it seems to get a little stuttery, which is something I hate.
$(function(){
var jqDockOpts = {align: 'left', duration: 200, labels: 'tc', size: 48, distance: 85};
$('#jqDock').jqDock(jqDockOpts);
});
You can easily change the positioning of the dock and labels as well as the initial size of the icons and a few other options. What I didn't like about this plugin is that it magnifies to the full size of the icon. The previous plugin gives you the ability to change the size it magnifies to. That's all there is to it!
jQuery OS X Stack and Drop Stack
This is probably my favorite navigation style out of the three shown in this tutorial. It's super lightweight (~1kb) and is a really creative "outside the box" method of navigation for a website. It might be a little awkward having the navigation in the bottom right or left of the browser window but it would certainly be creative and save lots of space. View Demo.
While writing this, I realized there are probably many people that won't like their navigation at the bottom of the page so I took a couple extra minutes and added a drop-down stack to the example files. This way the navigation springs out from top to bottom so it can now be used at the top of pages.
View Demo.
The HTML
The HTML is just as simple as the two dock examples. We'll place everything in a containing div and place all our images and titles, which are wrapped in links, within an unordered list.
Notice that I've placed an image before the unordered list. This is the basket image that the rest of the icons will be stacked behind.
The CSS
We'll position the main container and make sure the basket image has a higher z-index than the unordered list so everything stacks behind it. Also notice that I've given the basket image 35px of padding. This prevents the icons behind the basket from being clicked since the basket image is shorter than the icons. If you change the basket icon to something taller then you'll need to also change the padding.
.stack { position: fixed; bottom: 28px; right: 40px; }
.stack > img { position: relative; cursor: pointer; padding-top: 35px; z-index: 2; }
.stack ul { list-style: none; position: absolute; top: 5px; cursor: pointer; z-index: 1; }
.stack ul li { position: absolute; }
.stack ul li img { border: 0; }
.stack ul li span { display: none; }
.stack .openStack li span {
font-family: "Lucida Grande", Lucida, Verdana, sans-serif;
display:block;
height: 14px;
position:absolute;
top: 17px;
right:60px;
line-height: 14px;
border: 0;
background-color:#000;
padding: 3px 10px;
border-radius: 10px;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
color: #fcfcfc;
text-align: center;
text-shadow: #000 1px 1px 1px;
opacity: .85;
filter: alpha(opacity = 85);
}
/* IE Fixes */
.stack { _position: absolute; }
.stack ul { _z-index:-1; _top:-15px; }
.stack ul li { *right:5px; }
The titles wrapped in span tags are set to display:none so they'll be hidden when the page loads.
The JavaScript
We'll place the JavaScript in its own file since it's more than a couple lines. When the image outside the unordered list (the basket) is clicked, it uses jQuery's toggle function to animate the the list items and set their position based on the horizontal starting point + .75px then multiplied by 2. This gives us the nice curved spring action of the list items.
You could change the .75px or the multiplier (2) to customize how much it curves.
$(function () {
// Stack initialize
var openspeed = 300;
var closespeed = 300;
$('.stack>img').toggle(function(){
var vertical = 0;
var horizontal = 0;
var $el=$(this);
$el.next().children().each(function(){
$(this).animate({top: '-' + vertical + 'px', left: horizontal + 'px'}, openspeed);
vertical = vertical + 55;
horizontal = (horizontal+.75)*2;
});
$el.next().animate({top: '-50px', left: '10px'}, openspeed).addClass('openStack')
.find('li a>img').animate({width: '50px', marginLeft: '9px'}, openspeed);
$el.animate({paddingTop: '0'});
}, function(){
//reverse above
var $el=$(this);
$el.next().removeClass('openStack').children('li').animate({top: '55px', left: '-10px'}, closespeed);
$el.next().find('li a>img').animate({width: '79px', marginLeft: '0'}, closespeed);
$el.animate({paddingTop: '35'});
});
// Stacks additional animation
$('.stack li a').hover(function(){
$("img",this).animate({width: '56px'}, 100);
$("span",this).animate({marginRight: '30px'});
},function(){
$("img",this).animate({width: '50px'}, 100);
$("span",this).animate({marginRight: '0'});
});
});
Then when the user clicks the basket image again it runs the next function which reverses what we just did. I then added some additional animation to the list items and their titles to give them a little more user feedback, which of course can easily be removed.
And there you have it! A simple and flexible OS X style stack navigation for your website. :-D This script is also in the process of being converted into an easier to use plugin so keep an eye out for that.
Final Thoughts
Hopefully these examples will give you some ideas to be creative and break out of the mold when designing your next website or template. As you can see, jQuery is a powerful library that makes it easy to make our ideas a reality. With a potential upcoming competition based on "outside the box" designs, you might get started on some ideas to submit to ThemeForest. If you haven't submitted files before, it's very easy and can definitely be well worth your time! :-)
I want to thank Rey (from the jQuery team) and Steve for answering my call for help on Twitter so quickly. This is a prime example of how useful Twitter can be for designers and developers. If you aren't following Theme Forest or Nettuts on Twitter yet, now is a good time to do that. They're both websites with a ton of fantastic information. You can also follow me on Twitter if you'd like.
- Follow us on Twitter, or subscribe to the NETTUTS RSS Feed for more daily web development tuts and articles.
Related Posts
Check out some more great tutorials and articles that you might like
Plus Members
Source Files, Bonus Tutorials and
More for $9 a month for all TUTS+
sites in one subscription.





































User Comments
( ADD YOURS )Kevin Urrutia June 22nd
Very nice i am going to try this
( )Myfacefriends June 22nd
very useful thanks again guys!
( )DataMouse June 22nd
How cool is that effect!?
( )Awesome
Stephen Ainsworth June 22nd
Although i’m not a fan of mimicing operating systems, i’m sure these navigation techniques will come in handy.
Thanks!
( )b00m June 22nd
I luv jQuery! Tnx for sharing…worship!
( )Taylor Satula June 22nd
Very cool, much more seamless than the old one that harley alexander did.
( )His was very cool though
NickD June 22nd
Considering these are all based on existing navigation techniques – I wouldn’t really consider them ‘outside’ the box. Good write up’s none-the-less.
( )Daniel Groves June 22nd
Absolutely loving it… already getting ideas for future designs!
( )Jerichvc June 22nd
i say its playful
( )Greg June 22nd
awesome effects!
( )crysfel June 22nd
hahahahaha… funny
i like it, i agree with “Jerichvc”, its playful
( )Rahul Jadhav June 22nd
Thats awesome stuff. One of the best things to show your links
( )Joe June 22nd
Awesome dude, keep up.
( )Shane June 22nd
I like the stack and drop effect – very nice. I’m wondering where it could be used in a real-world situation.
( )Lamin Barrow June 22nd
I was also wondering where an effect like this might fit. It may be useful in a new ground breaking go and have fun type of website.
( )w1sh June 22nd
Think about that top-right basket. Notice how it’s icons drop out of it in directions of their own?
You could do something like this for a portfolio where your main links dropdown into a brainstorm effect.
Bah, I’m retardedly useless when it comes to explaining things.
( )Justin July 9th
I could totally see a shopping cart with your selected items doing this. Click on it to review what you’ve decided to purchase. Grab one and toss it out. Etc…
( )Mike June 22nd
Seriously cool — thanks guys!
( )Julien June 22nd
The Stack is really great
( )Btw, you should maybe add the .stop() function before to animate img & span, to avoid accumulation of animation.
EllisGL June 22nd
It double bounces when you come up from the bottom.
( )Jarel Remick June 22nd
Sean O recommended using jQuery’s stop() to fix this.
Here’s the new animation code with this implemented. http://pastie.org/520632
( )Paul June 22nd
Wow…this is amazing!
( )rishteria June 22nd
Really nice
( )Koka Koala June 22nd
cool
( )Dario Gutierrez June 22nd
Sure very nice effects navigation. I’m going to try this.
( )matheleo June 22nd
Really great tut, but one thing:
And your version drifts to right too fast for more items. You’ll have to shift it to the left, so that everything fits.
( )with the stacks, I’d change the horizontal offset to:
>> horizontal = horizontal*1.4 + 2.4
That’s much closer to Leopard’s stacks
choen June 22nd
thanks for sharing…. i love it…
( )Sean O June 22nd
I recommend the technique described here:
http://www.learningjquery.com/2009/01/quick-tip-prevent-animation-queue-buildup
to prevent animation queue buildup on the corner demos.
(roll over the icons a few times to see the issue)
( )Jarel Remick June 22nd
Thanks for the comments everyone!
@Sean O – Thanks for the recommendation.
I’ve implemented Sean O’s recommended fix (should have thought of it at time of writing) and here’s the animation code with jQuery’s stop() implemented.
http://pastie.org/520632
( )Dj June 22nd
Once upon a time, when dinosaurs roamed the land, I remember an “outside the box” scheme of navigating computer menu’s which displayed each topic in a horizontal row and required the user to click on the topic which would *then* display another vertical row of options to click. Like “star wars” it was a quantum leap from what we otherwise had; *but* was very non-intuitive and drove us all nuts until someone devised a “drop-down” menu triggered by simply “tabbing” to the category or subsequently by merely *”hovering”* over it. What an idea who’s time had come!
The basket, a great idea in an of itself, brings back unhappy memories of dinosaurs to me. Clicking to activate a menu is NOT intuitive in the current culture (without clunky “click me” instructions). Is there such a thing as a jQuery “hover-select” drop-down menu being activated from within another “hover-select?” I.E. could hovering over the basket cause it to expand slightly and eject the secondary “drop-up” menu which would then be navigable by hovering as well? That would be much more intuitive, as it is currently how most drop-down, nav-bars work.
( )Jarel Remick June 22nd
Yes, this is absolutely possible with jQuery (or just javascript). The point here is that many really cool ideas are possible with javascript.
Also, the stacks navigation idea may not work for you but might work for someone else. Navigations on todays websites take up a fairly significant amount of space and for certain types of websites like blogs, they aren’t used that often. So why not create something creative and space saving like a stacks navigation interface? Remember too that this doesn’t have to be navigation, this can be applied to all sorts of ideas. Information blurbs, photo stacks, etc.
( )sam June 22nd
Pretty celver, but it looks very Mickey Mouse to me, almost as bad as the trailing javascript stuff on mouse movements…lol
( )Kwaa June 22nd
Those stacks are awesome, thanks for another great tutorial!
( )Michael June 22nd
WOW! awesome effect
definetly will try to use this :>
thanks
( )Benjamin June 22nd
You need to change
$(’.stack li a’).hover(function(){
$(”img”,this).animate({width: ‘56px’}, 100);
$(”span”,this).animate({marginRight: ‘30px’});
},function(){
$(”img”,this).animate({width: ‘50px’}, 100);
$(”span”,this).animate({marginRight: ‘0′});
});
to
$(’.stack li a’).hover(function(){
$(”img”,this).stop().animate({width: ‘56px’}, 100);
$(”span”,this).stop().animate({marginRight: ‘30px’});
},function(){
$(”img”,this).stop().animate({width: ‘50px’}, 100);
$(”span”,this).stop().animate({marginRight: ‘0′});
});
then the stack will stop dancing
( )Jarel Remick June 22nd
Yup, listed above and posted at pastie.org – http://pastie.org/520632
( )Benjamin June 23rd
I frown on links!
jk sorry about the dub post
FireDart June 22nd
Saw the same thing here:
http://www.wizzud.com/jqDock/
But you actually explain how to do it!
Thanks!
( )Zim June 22nd
Amazing… I’ll try to pull it into the next version of my blog’s theme
( )Jhon Doe June 22nd
cool
( )chad June 22nd
Pretty cool. One thing to note is that some of the effects do not gratefully fail, leaving your user with a menu that is frustrating.
( )Jarel Remick June 22nd
The examples here are still usable without javascript. They might not be pretty but they work. With a little extra work, they could easily be made to look pretty even without javascript.
( )deedee June 22nd
This is what I’ve been looking for! Thankz!
( )Carl - Web Courses Bangkok Instructor June 22nd
THing is, it would take a equally sexy design to make the navigation feel at home…I better get started
( )Jacob Lee June 22nd
I agree with chad, but things like that aren’t too hard to fix, and it is a tutorial for learning, not a complete script.
Regardless, the dock isn’t a new thing, but the bin/bucket thing actually is a nice idea, could be useful on some of the more extensive admin panels.
( )Devin Rajaram June 22nd
I was going to use thing for my template for the competition on themeforest.
( )Julius June 22nd
Nice animation. great work man.
( )Rata June 22nd
¡Chulo!
I’m going to try this in autumn, the days are getting shorter already
Kind regards
( )Rata
Matthew Johnson June 22nd
This. Is. Awesome.
( )webangel78 June 23rd
Perfect animated navigation. jQuery is a great framework!
( )Vikram June 23rd
Hi looks interesting to me. How can i add/use this with by Blogger based blog. Can anybody help me out with the same – vikramdeo[at]nampblog[dot]com
( )Muhammad Adnan June 23rd
very nice ,
( )George Gina Lucy June 23rd
It’s not perfect yet, but the idea is brilliant!
( )grrrrrrr8 June 23rd
One word…. sweeeeeeeeeeeeeeeeeeeeeeet!!!
( )wayno007 June 23rd
Very cool. Thanks for the tut.
( )Martyn Web June 23rd
I would love to add these to a site, my only concern is whether people with no experience of a mac would realise the leopard dock was a navigation. It might help if on the roll over the icons automatically popped up.
Anyway it looks great regardless…
( )e11world June 23rd
I like the stack effect.. nice one! I noticed the bottom right one wasn’t working though.
( )J June 23rd
http://www.ndesign-studio.com/blog/design/css-dock-menu/
( )Simon June 23rd
Damn that’s incredibly nice ! Well at least I now know I don’t have to write it myself as I had decided a few days ago
( )Dave June 23rd
awesome effect
( )thomas June 23rd
hum… I’m pretty new to webdevelopement and i was wondering how can i put the stack in div. because i wante 3 stack on my website …
( )Matt June 24th
Very very nice tutorial!
( )BryanRegencia.com - Freelance Web Designer June 24th
Very Nice. Will try that in one of future projects.
( )Harley Alexander June 25th
Great to see my code recycled! You did a fantastic job!
( )Shaun Robinson June 26th
A couple of improvements could be made to the stack:
In the script, line 15, add this:
height: ‘50px’
Line 21, add this:
height: ‘79px’
Then in your HTML, specify the height and width of each image.
This means the images render quicker on page load, and your layout is not messed up if one or more of the images are unavailable.
( )Shaun Robinson June 26th
Oh, and lines 27 and 30 need height added too!
( )2pxborder June 29th
Thanks for sharing, really awesome sutff!
( )Kawsar Ahmad June 29th
its so great work…thanks…i like it
( )Steve June 29th
Very nice!!
( )ray June 29th
would it be possible to add a rollover effect? perhaps something like the fish eye rollover.
( )ray June 29th
sorry to clarify my previous comment. would it be possible to add a rollover effect to the stacks example?
( )SBosS June 30th
Great job
So, I would like to put vertical dock (example2) on the right side of the screen, how can I do ?
Thanks
( )chubweb July 7th
this is so cool, going to embed it in my website
many thx to you fren
( )Iva July 9th
I have a quick question: are multiple instances of the same type of this menu possible on a single page?
( )bowie July 14th
this posting could be used on the blog???
( )Mike July 15th
Awesome stuff! thanks much for the write up..I’ve been playing around with the stacks navigation and have one tiny problem. My app is using jquery 1.3 at the moment and the stacks-1.js doesn’t want to work with it =P Was wondering if you know how to fix it to work with jquery1.3 instead of 1.3.2 or atleast point me in the right direction to how I could fix the compatability issue =)
Thanks much!
( )iWantiPhone July 16th
My god, I’m getting left behind. There are so many new techniques that I didn’t know existed. Ok, need to learn it up asap.
( )Thanks for the post.
Diego July 16th
Hi.. that was nice, but i found an issue when working with masterpages and the icons stay freezed in firefox and IE .In IE it shows “null” is null or not an object…
Webpage error details
Message: ‘null’ is null or not an object
Line: 5 Char: 2 Code: 0
URI: http://www.adbees.com.br/js/stack.js
anyone know how to fix it?
( )It works fine in regular pages though
Diego July 23rd
Problem solved.. just put the in the content area and the script worksfine. Hope this helps others..
( )Ding July 27th
Would it be possible to use the stack as a shopping basket?
For example add an php array in the javascript code
Thanks for the post.
( )SBosS July 27th
Great Job
So, I’ve a problem with IE8.
On my page, I use nick stakenburg Lightivew using scriptaculous and prototype.
I use jQuery.noConflict(); to solve a problem beetween prototype and jquery dock. It works with prototype 1.6.0.3 but if I use prototype 1.6.1 Rc3 (needed to use Lightview on IE8) It doesn’t work (only on IE8 lightview ok, jqdock ko), all icons are on the same position (left).
Any idea to fix it ?
Do you know another dock using scriptaculous or prototype ? Or another lighbox as powerfull as Lightview using jquery ?
Thanks
( )JP July 28th
Firstly, awesome script man. Just what I’ve been looking for!
However, I have one problem. This script uses Div tags. The site I have been designing uses standard tags and it’s hierarchies. Still pretty green to all of this.
How can I implement this into a table data tag or something within my site without completely breaking the whole thing?
( )Joel August 2nd
This is nice—really, really nice—but it occurred to me that you didn’t add a .stop to the dropdown stack animation, so if you hover over one icon several times in succession, the caption animation will “stack up” rather than cancel each time. This would certainly be a helpful addition, and it looks cleaner as well.
( )qatar world August 12th
wow .. pretty awesome
( )Julien August 28th
Hi, I used the horizontal dock menu navigation as a bottom menu for my web site http://www.cluzeauwebdesign.com .Thanks a lot for this tut and for the plugin!
( )Jean-Marc August 29th
Hi,
I intend to use the second menu for our web site http://www.isotools.com
Where can I buy the icons displayed in your demo ?
Many thanks,
( )J.M.
jolly August 30th
not working plz help
where to put j.s . i am trying it on blogger
( )Mahbub September 6th
I’ve just loving this. Can’t wait to implement in some projects.
( )Rubin Geo Varghese September 11th
i would like to change the horizontal/vertical fisheye menu to a rotating circular fisheye menu ,,what should i do?
( )Joe October 11th
I might use this in a future project!
( )