blob: 6b794704130cf1c02c90a12a87bf6200cffb1f4f [file] [log] [blame]
$(document).ready(function(){
var sbHeight = $('#sidebar').height();
function stickSidebar() {
var $el = $('.footer'),
scrollTop = $(this).scrollTop(),
scrollBot = scrollTop + $(this).height(),
elTop = $el.offset().top,
elBottom = elTop + $el.outerHeight(),
visibleTop = elTop < scrollTop ? scrollTop : elTop,
visibleBottom = elBottom > scrollBot ? scrollBot : elBottom,
wHeight = $(this).height(),
sidebarOverflow = sbHeight - wHeight,
$sidebar = $("#sidebar .navbar"),
distance = (elTop - scrollTop);
if (wHeight < sbHeight) {
if (scrollTop > sidebarOverflow && wHeight < distance) {
$sidebar.css({'position':'fixed','bottom':0 });
} else if (wHeight >= distance) {
$sidebar.css({'position':'fixed','bottom':visibleBottom - visibleTop});
} else {
$sidebar.css({'position':'static'});
}
} else if (wHeight > sbHeight){
$sidebar.css({'position':'fixed', 'top':0});
}
}
$(window).on('scroll resize', stickSidebar);
});