1.0 alpha has been released! Learn More 1.0 Docs
menu
Become a Patron

Introduction

Scrollspy is a jQuery plugin that tracks certain elements and which element the user's screen is currently centered on. Our main demo of this is our table of contents on every documentation page to the right. Clicking on these links will also scroll the page to that element.

Table of Contents Structure


  <div class="row">
    <div class="col s12 m9 l10">
      <div id="introduction" class="section scrollspy">
        <p>Content </p>
      </div>

      <div id="structure" class="section scrollspy">
        <p>Content </p>
      </div>

      <div id="initialization" class="section scrollspy">
        <p>Content </p>
      </div>
    </div>
    <div class="col hide-on-small-only m3 l2">
      <ul class="section table-of-contents">
        <li><a href="#introduction">Introduction</a></li>
        <li><a href="#structure">Structure</a></li>
        <li><a href="#initialization">Intialization</a></li>
      </ul>
    </div>
  </div>
        

jQuery Plugin Initialization


  $(document).ready(function(){
    $('.scrollspy').scrollSpy();
  });
        

jQuery Plugin Options

Option Name Description
scrollOffset Offset for centering element when scrolled to. Default: 200
activeClass Class name to be added to the active link. Default: active
getActiveElement Function that returns a selector to add activeClass to. The parameter is the section id. Default:

  function(id) {
    return 'a[href="#' + id + '"]';
  }