table of contents contentify - Free Download Create A Table Of Contents From Headings - jQuery contentify

Free Download Create A Table Of Contents From Headings – jQuery contentify

Posted on

This time I will share jQuery Plugin and tutorial about Create A Table Of Contents From Headings – jQuery contentify, hope it will help you in programming stack.

table of contents contentify - Free Download Create A Table Of Contents From Headings - jQuery contentify
File Size: 5.42 KB
Views Total: 355
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   

contentify is a simple and lightweight jQuery plugin to automatically generate a table of content from the heading tags (h1, h2, etc) in your HTML document.

Use it as a user-friendly in-page navigation that allows your visitors to visit their favorite parts within the webpage.

Additionally, the plugin automatically assigns unique IDs to heading tags within the document so that your visitors can navigate between these page sections with a configurable smooth scroll effect.

How to use it:

1. Use heading tags to break down your long content (e.g. post, article, product description) into several sections.

01 <h1>Chapter 1</h1>
02   <h2>Section 1.1</h2>
03     <p>Content 1.1</p>
04   <h2>Section 1.2</h2>
05     <p>Content 1.2</p>
06 <h1>Chapter 2</h1>
07   <h2>Section 2.1</h2>
08     <p>Content 2.1</p>
09   <h2>Section 2.2</h2>
10     <p>Content 2.2</p>
11     ...

2. Create a container to hold the table of contents (typically at the top of the page).

1 <div id="toc"></div>

3. Insert the jQuery contentify plugin’s script jquery.contentify.js into the webpage, after loading the latest jQuery library.

1 <script src="/path/to/cdn/jquery.min.js"></script>
2 <script src="/path/to/src/jquery.contentify.js"></script>

4. Initialize the plugin to generate a default table of contents inside the container you just created.

1 $('#toc').contentify();

5. Apply custom styles to the table of contents.

1 #toc {
2   /* styles here */
3 }
4  
5 #toc a {
6   /* styles here */
7 }

6. Customize the title of the table of contents.

1 $('#toc').contentify({
2   title: 'My <a href="https://www.jqueryscript.net/tags.php?/Navigation/">Navigation</a>'
3 });

7. Determine which heading tags should be considered when building the table of contents.

1 $('#toc').contentify({
2   headingSelectors: ['h1', 'h2', 'h3', 'h4', 'h5']
3 });

8. Specify the duration of the scrolling animation.

1 $('#toc').contentify({
2   scrollDuration: 1000
3 });