This library automatically scans for heading elements like <h1>, <h2> and creates a list-based navigation menu with smooth scroll and scrollspy support.
<h1> through <h6>)1. Download and add Anchor.js to your HTML page.
<script src="anchor.js"></script>
2. Add an empty unordered list where you want the table of contents to appear:
<ul id="toc"></ul>
3. Organize your content with heading elements as follows:
<div class="container"> <h1>Title 1</h1> <p>Section 1...</p> <h2>Title 1.1</h2> <p>Section 1.1...</p> <h1>Title 2</h1> <p>Section 2...</p> </div>
4. Create a new Anchor object, targeting your list and specifying the headings.
const anchor = new Anchor('#toc', {
contentClass: 'container',
listHead: ['h1', 'h2'],
}); 5. Customize the Anchor with the following options:
const anchor = new Anchor('#toc', {
contentClass: 'container',
listHead: ['h1', 'h2'],
activeClass: 'active',
headClass: 'highlight',
defaultFontSize: {
h1: '48px',
h2: '36px'
},
defaultFontWeight: {
h1: 'bolder',
h2: 'bold'
},
offsetTop: 70
}); 06/12/2025
The post Create Dynamic Navigation Menus (TOC) for Long Content – Anchor.js appeared first on CSS Script.
ROCKFORD, Ill. (WTVO) — A house fire Sunday afternoon leaves one adult displaced. The Rockford…
The AI Workmate Concept can move and rotate to accomplish various tasks, but can it…
The magnetic pen case is pulling wedge duty in there. Lenovo has a few new…
We’ve been waiting five years for this follow-up to the X12 Detachable. | Image: Lenovo…
TAYLOR COUNTY, Texas (KTAB/KRBC) - A two-vehicle collision occurred south of Abilene Sunday afternoon. The…
Scream 7 has enjoyed a huge box office opening weekend, with nearly $100 million secured…
This website uses cookies.