Skip to content

Instantly share code, notes, and snippets.

@metinsaylan
Last active October 14, 2018 13:03
Show Gist options
  • Save metinsaylan/2c670af91b96f5ae379441f985972ac3 to your computer and use it in GitHub Desktop.
Save metinsaylan/2c670af91b96f5ae379441f985972ac3 to your computer and use it in GitHub Desktop.
JS-TOC - Javascript Generated Table of Contents
/* JS-TOC */
.js-toc-w:hover {
opacity: 1;
width: 220px;
}
.js-toc-w {
position: fixed;
top: 280px;
padding: 10px 15px 10px 10px;
opacity: .6;
font-size: 90%;
line-height: 1.3;
background: #fff;
width: 25px;
box-shadow: rgba(0,0,0,0.2) 0 0 5px;
border-top-right-radius: 6px;
border-bottom-right-radius: 6px;
transition: all .2s linear;
border-right: 2px solid #4caf50;
overflow: hidden;
}
.js-toc {
width: 200px;
list-style: none;
padding-left: 15px;
}
.js-toc li.js-toc-h {
text-transform: uppercase;
color: #aaa;
font-size: 12px;
transform: rotate(-90deg);
position: absolute;
left: -20px;
top: 50%;
border: 0;
}
.js-toc li {
padding: 3px;
border-bottom: 1px solid #ddd;
}
.js-toc li:last-child {
border: 0;
}
@media(max-width:1640px) {
.js-toc-w {
display: none;
}
}
<script>if(tc=".h-e",hs=".e-content h3",d=document,h=d.querySelectorAll(hs),h.length>0){for(toc=d.createElement("ul"),toc.className="js-toc list-style-none bx pad shadow",i=0;i<h.length;i++)l=d.createElement("a"),h[i].id=h[i].innerText.toLowerCase().replace(/[^a-z0-9áéíóúñü \.,_-]/gim,"").replace(/\s+/gim,"-").trim(),l.text=h[i].innerText,l.href=location.href.replace(location.hash,"")+"#"+h[i].id,hl=d.createElement("li"),hl.appendChild(l),toc.appendChild(hl);t=d.querySelector(tc),t.appendChild(toc)}</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment