diff options
| author | Jacob Thornton <[email protected]> | 2011-09-08 20:21:03 -0700 |
|---|---|---|
| committer | Jacob Thornton <[email protected]> | 2011-09-08 20:21:03 -0700 |
| commit | 5960711d0f79f7031b444bafba9a856c77f697bc (patch) | |
| tree | 71a29548549f7e69549b635f842359ac33116047 /docs/assets/js/application-scrollspy.js | |
| parent | 346122a0c7a883f1fcc1887899cf8bb37274c7f9 (diff) | |
| download | bootstrap-5960711d0f79f7031b444bafba9a856c77f697bc.tar.xz bootstrap-5960711d0f79f7031b444bafba9a856c77f697bc.zip | |
some more js love - update the docs with tabs/pills plugin
Diffstat (limited to 'docs/assets/js/application-scrollspy.js')
| -rw-r--r-- | docs/assets/js/application-scrollspy.js | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/docs/assets/js/application-scrollspy.js b/docs/assets/js/application-scrollspy.js new file mode 100644 index 000000000..1f0b7cebe --- /dev/null +++ b/docs/assets/js/application-scrollspy.js @@ -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); + +})
\ No newline at end of file |
