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.
Dragster.js is a tiny vanilla JavaScript drag and drop library that enables your users to…
A critical heap buffer overflow vulnerability (CVE-2026-48095 / GHSL-2026-140) has been disclosed in 7-Zip version…
A critical heap buffer overflow vulnerability (CVE-2026-48095 / GHSL-2026-140) has been disclosed in 7-Zip version…
LANSING, MICH. (WOWO) — State lawmakers have approved legislation that would give Mackinac Island expanded…
CLEVELAND, OHIO (WOWO) — A new report from the Lake Carriers’ Association says U.S.-flagged shipping…
A critical heap buffer overflow vulnerability has been disclosed in 7-Zip version 26.00, enabling attackers…
This website uses cookies.