split content into subpages

This commit is contained in:
Nils Schneider 2011-09-16 10:56:30 +02:00
parent b70774cee9
commit 5e114f37d6
10 changed files with 184 additions and 164 deletions

View file

@ -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;
}