Implementing this is quite simple, if the menu can be static and doesn't have to adjust when the window is resized; @skip405's example is a really good solution in this case (+1).
If the implementation has to adjust the menu dynamically on window resize, it get's tricky though... The window.onresize
event is fired quite often while the user scales the browser window, so a naive implementation (e.g. @skip405's approach executed on every event) would be too slow/expensive.
I'd solve the problem as follows:
- Calculate and add up the outer width of all links at the beginning.
- Append all available links to the "more" tab (cloning) so they can be shown/hidden dynamically. This is much faster than creating new (resp. destroying) DOM elements all the time.
- Bind a handler to the
onresize
event. In the handler, get the current menu width and compare it to the width of the links. Hide all links that don't fit in the menu and show their counterparts in the "more" tab. The same goes the other way round for showing links if the menu is wide enough.
Here's my implementation: http://jsfiddle.net/vNqTF/
Just resize the window and see what happens. ;) Note that the solution can still be optimized of course - it's just an example.