Giter VIP home page Giter VIP logo

dynamic-scrollspy's Introduction

Dynamic-Scrollspy

by Michael Tallino @psalmody

NPM version Downloads Join the chat at https://gitter.im/node-schedule/node-schedule

jQuery plugin to dynamically generate a .nav outline and setup Bootstrap scrollspy.

Installation

Include Bootstrap 3+ and jQuery 1.11+ or 2.0+.

Download from GitHub Project Page or:

Bower:

bower install dynamic-scrollspy

NPM:

npm install dynamic-scrollspy

Include:

<script type="text/javascript" src="build/dynamicscrollspy.min.js"></script>

Usage

Basic usage: setup a div or nav area to put the auto-generated nav outline in.

$('#somediv').DynamicScrollspy();

Options

Options may be specified at time of initiation:

$('#somediv').DynamicScrollspy({
  affix: true, //affix by default
  tH: 2, //lowest-level header to be included (H2)
  bH: 6, //highest-level header to be included (H6)
  exclude: false, //exclude from the tree/outline any H tags matching this jquery selector
  genIDs: false, //generate random IDs for headers?
  offset: 100, //offset from viewport top for scrollspy
  ulClassNames: 'hidden-print', //add this class to top-most UL
  activeClass: '', //active class (besides .active) to add to LI
  testing: false //if testing, append heading tagName and ID to each heading
})

Destroy / Rebuild

Destroy with:

$('#somediv').DynamicScrollspy('destroy');

Or just refresh by calling again. Settings will be saved from first call unless overriden at this time:

$('#somediv').DynamicScrollspy();

Horizontal Nav scrollspy

It is possible to use this package for a top/bottom navbar style scrollspy.

See /tests/horizontal.html for an example. Mainly, settings would require changes:

$('#somediv').DynamicScrollspy({
  affix: false, //needs to be false, instead setup navbar with affix if needed
  ulClassNames: 'navbar-nav', //the #somediv should be the navbar-collapse div
  tH: 2, //this is the default anyway
  bH: 2 //likely need to limit to one level of H* tags so the nav isn't unweildy
})

CSS

Some example CSS for styling a right-side list (like on Bootstrap's docs pages) Also see /tests/basic.html.

/* nav */
.nav {
  padding-left: 0px;
}
/* all anchors */
.nav > li > a {
  padding: 3px;
  border-left: 0px rgba(0,0,0,0);
}
/* first level */
.nav li >  a {
  padding-left: 10px;
}
/* second */
.nav .nav li >  a {
  padding-left: 20px;
  font-size:.9em;
}
/* third */
.nav .nav .nav li >  a {
  padding-left: 30px;
  font-size:.8em;
}
/* fourth */
.nav .nav .nav .nav li >  a {
  padding-left: 40px;
}
/* fifth */
.nav .nav .nav .nav .nav li >  a {
  padding-left: 50px;
}
/* active link */
li.active > a {
  font-weight:bold;
  border-left: 2px solid gray;
}
/* hide second level lists */
.nav .nav {
  display:none;
}
/* show second-level when active */
.nav > .active > .nav {
  display: block;
}

Contributing

Feel free! Fork it, create a branch, etc.

dynamic-scrollspy's People

Contributors

psalmody avatar peteflorence avatar

Watchers

James Cloos avatar Thomas Luo avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.