Visit our live page:
After incorporating some jQuery code (with the help of StackOverflow), I have managed to automate the linking of my chapter titles. For instance, clicking on "Chapter Three" will take you directly to the third chapter on the page.
If you look at the live page, you'll notice that my sticky navigation bars obstruct the beginning of each chapter. I am looking for a way to offset each jQuery anchor by 200px vertically so that the starting point of each chapter is correctly displayed.
Here is the HTML structure for the Chapters Nav:
<nav id="chapters">
<ul>
<li><a href="#">Chapter One</a></li>
<li><a href="#">Chapter Two</a></li>
<li><a href="#">Chapter Three</a></li>
</ul>
</nav>
This is how the Article section is structured in HTML:
<article class="clearfix">
<h1>Chapter One</h1>
...
</article>
Below is the jQuery code snippet being used:
// Chapters - locate the navigation and headers
var nav = $('#chapters li a'),
articles = $('#main article > h1');
// Assigning unique ids/hrefs to each chapter
nav.each(function (i) {
nav.eq(i).attr('href', '#article-' + i);
articles[i].id = 'article-' + i;
});