Fixed Table of Contents Plugin with jQuery
File Size: | 20.1KB |
---|---|
Views Total: | 2500 |
Last Update: | |
Publish Date: | |
Official Website: | Go to website |
License: | MIT |

A simple and useful jQuery plugin for adding a fixed table of contents drop-down menu on the top of your webpage. It can be used as a content navigation that provides your visitors with an easy way to quickly navigate to other content areas.
How to use it:
1. Markup
<div id="toc-holder" class="toc-holder"> <a href="#" class="toc-link" id="toc-link"><span>▼</span> Table of Contents</a> <ul id="toc" class="toc"> <li class="toc-h1">Main Menu 1 <ul class="toc-sub closed"> <li><a href="#section1-1">Sub Menu 1.1</a></li> <li><a href="#section1-2">Sub Menu 1.2</a></li> </ul> </li> <li class="toc-h1"><a href="#section2">Main Menu 2</a> <ul class="toc-sub closed"> <li><a href="#section2-1">Sub Menu 2.1</a></li> <li><a href="#section2-2">Sub Menu 2.2</a></li> </ul> </li> ... </ul> </div>
2. The CSS
.toc-holder { width: 18%; min-width: 360px; } .toc-holder a:link, .toc-holder a:visited { text-decoration: none; -webkit-transition: all .7s ease; -moz-transition: all .7s ease; -o-transition: all .7s ease; -ms-transition: all .7s ease; transition: all .7s ease; } .toc-holder li li a:link, .toc-holder li li a:visited { padding-left: 60px; } .toc-holder li li li a:link, .toc-holder li li li a:visited { padding-left: 90px; } .toc-holder li a:hover { background: #666; border-left: solid 5px transparent; } .toc-holder { position: fixed; margin-top: -70px; } .toc-link:link,.toc-link:visited { color: white; position: relative; display: block; z-index: 20; height: 40px; line-height: 40px; padding-left: 10px; width: 100%; background: #444; } .toc-link:hover { background: #666; } .toc-link span { font-size: 16px; margin-right: 5px; display: inline-block; -webkit-transition: -webkit-transform .4s ease; -moz-transition: -moz-transform .4s ease; -o-transition: -o-transform .4s ease; -ms-transition: -ms-transform .4s ease; transition: transform .4s ease; } .toc-link span.rotate { -webkit-transform: rotate(180deg); -moz-transform: rotate(180deg); -o-transform: rotate(180deg); -ms-transform: rotate(180deg); transform: rotate(180deg); } .toc { position: absolute; z-index: 10; width: 103%; background: #222; padding: 40px 0 20px 0; } .toc-h1,.toc-h1 ul { list-style: none; margin: 0; padding: 0; } .toc-h1 a:link,.toc-h1 a:visited { color: white; padding: 5px 20px 5px 30px; display: block; } .closed { display: block; }
3. Include jQuery library and fixedTOC.js
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> <script src="js/jquery.fixedTOC.js"></script>
4. Call the plugin on the '#toc' element
<script> $('#toc').fixedTOC({ menuOpens: 'click', // or 'mouseenter' scrollSpeed: 1000, menuSpeed: 300, useSubMenus: true, resetSubMenus: true, topLinkWorks: true }); </script>
This awesome jQuery plugin is developed by impressivewebs. For more Advanced Usages, please check the demo page or visit the official website.