SliderNav: iPhone Style Contact Lists Using jQuery and CSS
By Monji in General + Tutorials49 CommentsThis effect is actually from Techi.com, a new blog launched by the guys at WebDesignerDepot, where they use it to display their popular tags in the sidebar. I wanted to see how easy (or hard) it was to recreate using JQuery and CSS, and it turns out that it’s pretty simple to do. I’ve packed it into a neat little plugin so you hopefully you can make some use of it!
Updated May 25: I’ve just added a new option that displays arrows above and below the SliderNav object. This is used to navigate longer sections for users that do not have a mouse wheel (or those who are on a mobile browser).
SliderNav is a JQuery plugin that lets you add dynamic, sliding content using a vertical navigation bar (index). It is made mainly for alphabetical listings but can be used with anything, though longer words can look a bit awkward. The plugin automatically adds the navigation and sets the height for the object based on how tall the navigation is, in order to make sure users have access to the entire list. I also used the overflow: auto; property for the actual content so you can use your mousewheel to scroll through the content as well.
The plugin has been tested (and works fine) on Firefox 3, Chrome 5, IE7, Safari 4 and Opera 10.
Download
You can download the full source, minified version, css file, or view the example online.
Usage Instructions
SliderNav is super easy to use, but first you have to load JQuery, the plugin and the relevant CSS file in order to use it:
1 2 3 | <link rel="stylesheet" type="text/css" href="slidernav.css" media="screen, projection" /> <script type="text/javascript" src="jquery-1.4.2.js"></script> <script type="text/javascript" src="slidernav.js"></script> |
After you’ve done that, create the section content in HTML using the following structure (you can name your element anything):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | <div id="slider"> <div class="slider-content"> <ul> <li id="a"><a name="a" class="title">A</a> <ul> <li><a href="/">Adam</a></li> <li><a href="/">Alex</a></li> <li><a href="/">Ali</a></li> <li><a href="/">Apple</a></li> <li><a href="/">Arthur</a></li> <li><a href="/">Ashley</a></li> </ul> </li> <li id="b"><a name="b" class="title">B</a> <ul> <li><a href="/">Barry</a></li> <li><a href="/">Becky</a></li> <li><a href="/">Biff</a></li> <li><a href="/">Billy</a></li> <li><a href="/">Bozarking</a></li> <li><a href="/">Bryan</a></li> </ul> </li> etc... </ul> </div> </div> |
Once you’ve set the HTML, it’s simply a matter of calling the sliderNav function for the element you’ve just created:
1 2 3 4 5 | <script type="text/javascript"> $(document).ready(function(){ $('#slider').sliderNav(); }); </script> |
Custom Options
The first of the configurations is height – set this to a pixel value if you wish to override the automatic detection based on the vertical navigation (you may need to change the min-height in the CSS too). Also by default, the plugin will generate an alphabetical navigation that uses all 26 letters of the English alphabet, however you can also use custom items using the following code:
1 | $('#slider').sliderNav({items:['item1','item2','item3'], height:'200'}); |
You can also set arrows to true (default) or false, which displays arrows above and below the slider object to allow scrolling longer sections. Click on an arrow will scroll the object by it’s height – I used this method to keep code to the minimum, as anything smoother/nicer-looking required a lot more code. The last customizable option is debug, which can either be true or false. This adds a little bit of text on the bottom of the slider that shows how many pixels the current offset is (was useful during early development, probably not anymore).
Possible Use Cases
I believe this navigation can be useful in certain circumstances, mainly where you’re trying to show a lot of information that has been organized alphabetically (or by date) in a small area. For instance, it could be used to create a WordPress widget that lists all posts alphabetically or better yet, a widget for complete archives categorized by date. I’m not sure how much better it would be than traditional means of navigation but it’s certainly worth trying out.
Conclusion
As usual, please leave any feedback if you have it. I’m still very new to the JQuery plugin scene so there may be bugs or mistakes – if you find one, please mention it in the comments.
If you haven’t yet, please subscribe to the RSS feed and follow us on Twitter for more plugins and other useful bits!








Hi!
I want to change the letters list on the right to letter in other languages. Where do I find the file that the list is in?
I changed the index file so it looks like that
א
but on the right there are still the letters A-Z
Hey Omer,
The actual list of letters is in the JQuery plugin file (slidernav.js or slidernav-min.js), however you can change the items when you call the slidernav function, like:
Where item1, item2, etc. are the letters you want to use. Just make sure to update the anchor links in the HTML as well.
Hope that helps!
I managed to change the letters but the on mouse over effect doesn’t happened when it come to the letters that are not in English.
OK, now it works.
Thanks for a nice plugin!
Great to hear that Omer, I’m glad you got it to work! I’ll be posting some updates/features to the plugin in the next couple of days so be on the lookout for those.
Great work! going to use it on upcoming project :)
Excellent, I’m happy to hear that! Send me a link or post it here so I can see how it turns out.
Nice work … keep it up .
Thanks Nikesh, I appreciate it!
Great plugin! Unfortunately, when a section’s list is too long to show without scrolling, it’s impossible on a touch sensitive device. It would be nice to see two links that allowed for scrolling.
You brought up an excellent point I overlooked – it was impossible to scroll through longer sections on a mobile browser or for people without a mouse wheel.
I’ve added an optional set of up and down arrows to the element that provide basic scrolling functionality. I opted to not use complex animation or even scrolling on mouseover, as that required a bit more code. I want to keep this plugin as light as possible!
Is it possible to use spaces in the slider items?
for example if I try and do:
sliderNav({items:['firstname lastname']
It will work on the menu on the right side of the slider, but nothing will happen when I click on it.
Any ideas?
With the current setup, it won’t work because when you click the link, it is searching for the section with an ID of “firstname lastname”, like so:
Because of HTML limitations, you can’t have an ID value that contains a space, it simply won’t work.
The easiest solution I can think of is to use
slidernav({items:["firstname-lastname"]});and alter the code so when you inject that value into the list, you replace the dash with a space instead (in the plugin JS).Hope that helps!
Hi! With doctype in IE7 SliderNav not work correctly. Not working slow scrolling and arrows.
DOCTYPE DTD XHTML 1.0
I add DOCTYPE with specification in your example html file and scroll in IE is broken. How to fix it special for IE?
Hey Ns1 – I haven’t tried it out with the doctype set – let me try it out and I’ll report back. Doctype does funny things to IE7 though, it may just be an unfortunate bug of the SliderNav plugin.
Thanks for pointing it out!
Could you solve this problem ? If so…how ?!
I deleted link on w3.org in DOCTYPE and changed all css bugs for IE only.
What about the animation ? After you changed the DOCTYPE, did it continue to work fine? Could you please send me the files you have changed ? My e-mail is: wilkerp@ig.com.br
This is great!
I’m trying to build a web app specifically for use on an iPhone/iPad; should I use your widget to build it? How would I make your widget take up the full screen?
Thanks!
Hey Davel, that’s a great question. Personally, I wouldn’t recommend this for iPhone/iPad, as it doesn’t have the familiar drag functionality of the iOS interface. What I would suggest, however, is jQTouch – check that out and see if it fits your needs!
About the DOCTYPE problem, do you have any clue how to solve it ? Thanks in advance.
Hi,
i like your nav really ! It’s great and a substantial progress in the web usability!
But is it possible to give sliderNav() an auto-height value? It should use the complete height of my different div containers and should auto-resize if the user changes the layout.
This is an amazing plugin, just used it on my recent project http://Page-Directory.com
It is great for fitting in lists in a small area and better yet it provides great way to navigate.
Thank you for this plugin
- Brain