mirror of
https://github.com/seigler/dash-docs
synced 2025-07-27 17:56:16 +00:00
split content into subpages
This commit is contained in:
parent
b70774cee9
commit
5e114f37d6
10 changed files with 184 additions and 164 deletions
55
lib/app.js
55
lib/app.js
|
@ -1,41 +1,22 @@
|
|||
$(document).ready(function(){
|
||||
var docked;
|
||||
var menu = document.getElementById('menu');
|
||||
var init = menu.offsetTop;
|
||||
|
||||
// scroll spy logic
|
||||
// ================
|
||||
|
||||
var activeTarget,
|
||||
position = {},
|
||||
$window = $(window),
|
||||
nav = $('body > .topbar li a'),
|
||||
targets = nav.map(function () {
|
||||
return $(this).attr('href');
|
||||
}),
|
||||
offsets = $.map(targets, function (id) {
|
||||
return $(id).offset().top;
|
||||
});
|
||||
|
||||
|
||||
function setButton(id) {
|
||||
nav.parent("li").removeClass('active');
|
||||
$(nav[$.inArray(id, targets)]).parent("li").addClass('active');
|
||||
}
|
||||
|
||||
function processScroll(e) {
|
||||
var scrollTop = $window.scrollTop() + 10, i;
|
||||
for (i = offsets.length; i--;) {
|
||||
if (activeTarget != targets[i] && scrollTop >= offsets[i] && (!offsets[i + 1] || scrollTop <= offsets[i + 1])) {
|
||||
activeTarget = targets[i];
|
||||
setButton(activeTarget);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nav.click(function () {
|
||||
processScroll();
|
||||
});
|
||||
|
||||
processScroll();
|
||||
|
||||
$window.scroll(processScroll);
|
||||
window.onscroll = function () {
|
||||
if (!docked && (menu.offsetTop - scrollTop() < 0)) {
|
||||
menu.style.top = 0;
|
||||
menu.style.position = 'fixed';
|
||||
docked = true;
|
||||
} else if (docked && scrollTop() <= init) {
|
||||
menu.style.top = init + 'px';
|
||||
menu.style.position = 'absolute';
|
||||
docked = false;
|
||||
}
|
||||
};
|
||||
|
||||
});
|
||||
|
||||
function scrollTop() {
|
||||
return document.body.scrollTop || document.documentElement.scrollTop;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue