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:
39
docs/assets/js/application-scrollspy.js
Normal file
39
docs/assets/js/application-scrollspy.js
Normal 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);
|
||||
|
||||
})
|
Reference in New Issue
Block a user