bootstrap3.navbar
is used in the menu above.
Elixon TOC generator is easy-to-use jQuery plugin that automatically creates smart HTML table of contents. It automatically tracks window scrolling and highlights currently viewed chapters.
head
element:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" type="text/javascript"></script>
<link href="…/jquery.toc.css" type="text/css" rel="stylesheet"/>
<script src="…/jquery.toc.js" type="text/javascript"></script>
<div toctemplate="elegant"></div>
That's it! You did it! Keep reading for more examples and other tricks.
Generate elegant
TOC from h2
and h3
elements that are inside the element with id article
.
<div tocfrom="#article h2, #article h3" toctemplate="simple"></div>
Generate modern
TOC appended to an element with id myElement
from h2
and h3
elements that are inside the element with id article
.
$("#myElement").toc("#article h2, #article h3", "modern");
You can generate a Table Of Contents using other elements then h1
, h2
and so on.
Simply specify the ordered array with jQuery selectors.
Consider this example
<a title="About Us" class="lvl1">Chapter 1</a>
<p>Lorem ipsum …</p>
<a title="Company" class="lvl2">Chapter 1.1</a>
<p>Lorem ipsum …</p>
<a title="Location" class="lvl2">Chapter 1.2</a>
<p>Lorem ipsum …</p>
<a title="Map" class="lvl3">Chapter 1.2.1</a>
<p>Lorem ipsum …</p>
<a title="Products" class="lvl1">Chapter 2</a>
<p>Lorem ipsum …</p>
Generate headings from three levels of HTML links. Use the title
attribute on the link
as TOC item label.
$("#myElement").toc(["a.lvl1", "a.lvl2", "a.lvl3"], function() {return $(this).attr("title");});
<!doctype html> <html> <head> <title>Example Domain</title> <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" type="text/javascript"></script> <link href="…/jquery.toc.css" type="text/css" rel="stylesheet"/> <script src="…/jquery.toc.js" type="text/javascript"></script> </head> <body> <div> <h1>Table Of Contents</h1> <div toctemplate="default:nohilite"></div> <h1>Chapter 1</h1> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p> <h2>Chapter 1.1</h2> <p>Fusce ut iaculis risus. Quisque vehicula elementum neque.</p> <h1>Chapter 2</h1> <p>Ac feugiat leo vehicula eget. Aenean rutrum iaculis.</p> <h2>Chapter 2.2</h2> <p>Phasellus velit tortor, mollis ullamcorper purus.</p> </div> </body> </html>
<HTMLELEMENT [ tocfrom="SELECTOR" ] [ toctemplate="TEMPLATENAME" ] [ tocoffset="OFFSET" ]/>Example:
<div tocfrom=".contents h1, .contents h2" toctemplate="modern"></div>
span
, div
, ….:
(eg. elegant:collapsible:roman
).
default
(default) Supported features: nohilite collapsible nonum mixed roman alpha disc square
modern
Supported features: nohilite collapsible nonum mixed roman alpha disc square
elegant
Supported features: nohilite collapsible nonum mixed roman alpha disc square
simple
Supported features: nohilite collapsible
bootstrap3.dropdown
Supported features: nohilite
bootstrap3.buttons
Supported features: nohilite
bootstrap3.pills
Supported features: nohilite
bootstrap3.pills.stacked
Supported features: nohilite
bootstrap3.pills.justified
Supported features: nohilite
bootstrap3.pager
Supported features: nohilite
bootstrap3.list
Supported features: nohilite
bootstrap3.navbar
Supported features: nohilite
jQueryObject.toc([ARG[, ARG[, …]]]);Example:
$("#mainTOC").toc("modern");Where ARG can be one of
function(info)
that extracts and returns the text from an element to be displayed in TOC. Default: function(info) {return $(this).text();}
:
(eg. elegant:collapsible:roman
).
default
(default) Supported features: nohilite collapsible nonum mixed roman alpha disc square
modern
Supported features: nohilite collapsible nonum mixed roman alpha disc square
elegant
Supported features: nohilite collapsible nonum mixed roman alpha disc square
simple
Supported features: nohilite collapsible
bootstrap3.dropdown
Supported features: nohilite
bootstrap3.buttons
Supported features: nohilite
bootstrap3.pills
Supported features: nohilite
bootstrap3.pills.stacked
Supported features: nohilite
bootstrap3.pills.justified
Supported features: nohilite
bootstrap3.pager
Supported features: nohilite
bootstrap3.list
Supported features: nohilite
bootstrap3.navbar
Supported features: nohilite
["h1", "h2", "h3", "h4", "h5", "h6"]
. If no SELECTOR or JQOBJECT is specified then this array is used as SELECTOR.headers
same as SELECTOR or JQOBJECT above.callback
custom callback function($active) called everytime when TOC item is highlighted upon click or scroll.labeler
same as LABELER above.template
same as TEMPLATENAME above.offset
same as OFFSET above.tocLevels
same as MAPPING above.className
additional class names to add on the TOC root element.nohilite
- switch highlighting of currently viewed chapter off.collapsible
- collapse subchapters in other branches then the current viewed one.nonum
- don't use CSS list style numbering.mixed
- mixed alpha and numeric numbering style.roman
- roman numberig style.alpha
- alpha numbering style.disc
- use a disc symbol in front of every item.square
- use a square symbol in front of every item.