1
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-09-27 13:59:06 +02:00

some more js love - update the docs with tabs/pills plugin

This commit is contained in:
Jacob Thornton
2011-09-08 20:21:03 -07:00
parent 346122a0c7
commit 5960711d0f
11 changed files with 143 additions and 120 deletions

View File

@@ -0,0 +1,39 @@
// scroll spy logic
// ================
$(function () {
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);
})