Skip to content

Instantly share code, notes, and snippets.

@tomhodgins
Created November 12, 2020 21:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomhodgins/db4d3b8eea4598aa150ba490052f3b0c to your computer and use it in GitHub Desktop.
Save tomhodgins/db4d3b8eea4598aa150ba490052f3b0c to your computer and use it in GitHub Desktop.
function html(strings, ...expressions) {
return document.createRange().createContextualFragment(
strings.reduce((output, string, index) =>
output + expressions[index - 1] + string
)
)
}
document.body.append(
html`
<style>
[data-overview] {
position: fixed;
top: 0;
left: 0;
background: rgba(255, 255, 255, .8);
padding: 1em;
max-height: 100vh;
overflow-y: auto;
}
[data-overview] a {
color: black;
}
:target {
background: rgba(255, 255, 0, .1);
}
</style>
<nav data-overview>
<ul>
${
Array.from(
document.querySelectorAll('[id]'),
({id}) => `<li><a href="#${id}">${id}</a>`
).join('')
}
</ul>
</nav>
`
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment