Fixed the anchor offset issue.
This commit is contained in:
parent
35f1c3a9e8
commit
4c68d18b10
2 changed files with 15 additions and 11 deletions
|
|
@ -28,17 +28,20 @@ document.addEventListener('DOMContentLoaded', () =>
|
|||
/**
|
||||
* @type {NodeListOf<HTMLElement>}
|
||||
*/
|
||||
const sections = document.querySelectorAll('.section');
|
||||
const sections = document.querySelectorAll('section');
|
||||
|
||||
sections.forEach(section =>
|
||||
{
|
||||
if (section.id)
|
||||
const anchorTarget = section.querySelector('[id^="section-"]');
|
||||
const anchorHeader = section.querySelector('h1,h2');
|
||||
|
||||
if (anchorTarget && anchorHeader)
|
||||
{
|
||||
const anchor = document.createElement('a');
|
||||
anchor.className = 'anchor-link';
|
||||
anchor.href = `#${section.id}`;
|
||||
anchor.innerHTML = ' # ';
|
||||
section.appendChild(anchor);
|
||||
const anchorLink = document.createElement('a');
|
||||
anchorLink.className = 'anchor-link';
|
||||
anchorLink.href = `#${anchorTarget.id}`;
|
||||
anchorLink.innerHTML = ' # ';
|
||||
anchorHeader.appendChild(anchorLink);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue