; (function ($, window, document, undefined) {
$.fn.extend({
scrollspy: function (options) {
// Define our defaults
var defaults = {
namespace: 'scrollspy',
activeClass: 'active',
animate: false,
duration: 1000,
offset: 0,
container: window,
replaceState: false
};
// Add any overriden options to a new object
options = $.extend({}, defaults, options);
// Adds two numbers together
var add = function (ex1, ex2) {
return parseInt(ex1, 10) + parseInt(ex2, 10);
}
// Find our elements
var findElements = function (links) {
// Declare our array
var elements = [];
// Loop through the links
for (var i = 0; i < links.length; i++) {
// Get our current link
var link = links[i];
// Get our hash
var hash = $(link).attr("href");
// Store our has as an element
var element = $(hash);
// If we have an element matching the hash
if (element.length > 0) {
// Get our offset
var top = Math.floor(element.offset().top),
bottom = top + Math.floor(element.outerHeight());
// Add to our array
elements.push({ element: element, hash: hash, top: top, bottom: bottom });
}
}
// Return our elements
return elements;
};
// Find our link from a hash
var findLink = function (links, hash) {
// For each link
for (var i = 0; i <...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Get Fiddle Pages with PRO
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.