Easy as A,B,C – dynamic A to Z indexes - Customizing the script
(Page 5 of 5 )
The script needs several classes in the CSS and the appropriate IDs on the HTML element to add the effect. This was done to allow complete control over the look and feel without changing the JavaScript. The IDs make the script a lot faster as we can access elements by their ID rather than looping through all of them.
The IDs are:
atoz | The A to Z list navigation; this can be in any format, as the script loops through the links contained within it. The best option is an unnumbered list, though. |
contents | The element containing all the different sections from A to Z, normally a DIV. |
The classes are:
hidden | hides the section to which it is applied |
shown | shows the section that was previously hidden |
current | applied to the current link |
dohover | applied to the atoz element to indicate that the effect should be applied when you mouse over it, and not only when you click it. |
All these settings can be changed in the first few lines of the script:
// check if necessary elements are available
var n=document.getElementById('atoz');
var c=document.getElementById('contents');
// Define the classes in use to show and hide the elements
var hc='hidden';
var sc='shown';
var cc='current';
var mc='dohover';
Saving even more screen estate Long lists are boring to look at, and the need to scroll the screen can be very annoying. We aligned our A to Z navigation horizontally; why not do the same with the content lists? All we need to add is a style that defines a width for each of the list elements and floats them to the left:
#contents.columns li{
float:left;
width:10em;
}
The link pointing back to the navigation needs to clear each float, otherwise following sections might be indented:
#contents.columns p.back2{
clear:both;
}
Now we have a dynamic A to Z index that takes up the least possible screen estate (example:columnatoz.html). The list items do get arranged horizontally, not vertically. If we wanted to arrange them vertically, we’d need to resort to more excessive use of CSS and messy HTML suffering from “classitis” (the overuse of classes in the HTML, effectively mixing structure with presentation). There is an article on the subject of multicolumn lists explaining all the ins and outs at Community MX [2].
Links
[1] http://www.jimthatcher.com/skipnav.htm - Internet explorer bug concerning anchors and keyboard navigation.
[2] http://www.communitymx.com/content/article.cfm?cid=27F87 - Multi column lists with CSS.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |