Skip to content

Commit

Permalink
Add an (aborted) attempt to have a fixed TOC.
Browse files Browse the repository at this point in the history
  • Loading branch information
romac committed Nov 27, 2011
1 parent e8df609 commit 6376a7c
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
27 changes: 25 additions & 2 deletions _assets/stylesheet.css
Expand Up @@ -10,7 +10,7 @@ body
font-family: Georgia, serif;
line-height: 1.6;
width: 720px;
margin: 0 auto;
margin: 0 0 0 400px;
color: #222;
}

Expand Down Expand Up @@ -48,11 +48,34 @@ section > section {
padding-bottom: 30px;
}

#TOC {
position: absolute;
top: 209px;
left: 0;
height: auto;
overflow: hidden;
padding: 20px;
font-size: 0.9em;
font-family: 'Lato';
}

#TOC ul {
padding-left: 20px;
}

#TOC > ul > li > ul > li {
width: 250px;
}

#TOC > ul > li > ul > li > ul {
display: none;
}

#TOC > ul > li:first-child {
display: none;
}

.highlight {
font-family: Monaco, Menlo, Droid Sans, monospace;
font-size: 0.9em;
}
}
26 changes: 26 additions & 0 deletions _assets/template.html
Expand Up @@ -69,6 +69,7 @@ <h4 class="date">$date$</h4>
$if(toc)$
$if(html5)$
<nav id="$idprefix$TOC">
<h1>Table of contents</h1>
$toc$
</nav>
$else$
Expand All @@ -81,5 +82,30 @@ <h4 class="date">$date$</h4>
$for(include-after)$
$include-after$
$endfor$
<script>
window.onscroll = ( function()
{
return;

var pinned = false,
$toc = document.getElementById( 'TOC' ),
offset = 200;

return function()
{
if( !pinned && document.body.scrollTop > offset )
{
$toc.className = 'pinned';
pinned = true;
}
else if( pinned && document.body.scrollTop < offset )
{
$toc.className = '';
pinned = false;
}
};

} )();
</script>
</body>
</html>

0 comments on commit 6376a7c

Please sign in to comment.