Last active
February 19, 2016 19:14
-
-
Save daniellmb/53e3f75d142980e44c2f to your computer and use it in GitHub Desktop.
Dynamically inject heading links
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* unobtrusively style deep-linking heading anchors */ | |
.anchor { | |
color: gray; | |
display: inline-block; | |
margin-left: -1rem; | |
opacity: 0; | |
padding-right: 0.1rem; | |
-webkit-transition: opacity cubic-bezier(0,1,.35,.96) 1s; | |
-moz-transition: opacity cubic-bezier(0,1,.35,.96) 1s; | |
-ms-transition: opacity cubic-bezier(0,1,.35,.96) 1s; | |
} | |
h2:hover .anchor, | |
h3:hover .anchor, | |
h4:hover .anchor, | |
h5:hover .anchor, | |
h6:hover .anchor { | |
opacity: 1; | |
text-decoration: none; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// auto-link page headings 0.1 KB minified | |
[].forEach.call(document.querySelectorAll('h2,h3,h4,h5,h6'), function(tag) { | |
tag.id && (tag.innerHTML = '<a href="#' + tag.id + '"class="anchor">¶</a>' + tag.innerHTML) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment