mirror of
https://github.com/tenrok/bootstrap.git
synced 2026-06-02 16:04:07 +03:00
add bootstrap-scrollspy
This commit is contained in:
@@ -1,39 +0,0 @@
|
||||
// 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);
|
||||
|
||||
})
|
||||
@@ -6,6 +6,12 @@ $(document).ready(function(){
|
||||
$('body').dropdown() // catch any dropdowns on the page
|
||||
|
||||
|
||||
// Scrollspy
|
||||
// =========
|
||||
|
||||
$('body > .topbar').scrollSpy()
|
||||
|
||||
|
||||
// table sort example
|
||||
// ==================
|
||||
|
||||
|
||||
Reference in New Issue
Block a user