Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Solo] Add anchor link to content headings #2

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions assets/css/screen.css
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,22 @@ hr {
}
}

.anchor-link {
opacity: 0;
text-decoration: none;
margin-left: 0em;
}

h1:hover .anchor-link,
h2:hover .anchor-link,
h3:hover .anchor-link,
h4:hover .anchor-link,
h5:hover .anchor-link,
h6:hover .anchor-link {
opacity: 1;
text-decoration: none;
}

/* Custom CTA
/* ---------------------------------------------------------- */

Expand Down
15 changes: 15 additions & 0 deletions assets/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,18 @@ function initParallax() {
(function () {
pagination(true, initParallax);
})();

(function (window, document) {
var addAnchors = () => {
var headings = document.querySelectorAll('.gh-content h1, .gh-content h2, .gh-content h3, gh-.content h4, .gh-content h5, .gh-content h6')
headings.forEach((heading) => {
heading.insertAdjacentHTML('beforeend', `
<a href="#${heading.id}" class="anchor-link">
<svg width="1em" height="0.85em" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13.828 10.172a4 4 0 00-5.656 0l-4 4a4 4 0 105.656 5.656l1.102-1.101m-.758-4.899a4 4 0 005.656 0l4-4a4 4 0 00-5.656-5.656l-1.1 1.1"></path></svg>
</a>
`)
})
}

document.addEventListener('DOMContentLoaded', addAnchors)
})(window, document);