Skip to content

Instantly share code, notes, and snippets.

@bchumney
Created October 31, 2013 17:32
Show Gist options
  • Save bchumney/7253738 to your computer and use it in GitHub Desktop.
Save bchumney/7253738 to your computer and use it in GitHub Desktop.
Sticky Sidebar for Blog Section
$(document).ready(function(){
var t, b, w, h;
if ($('#sideColumn').length > 0) {
var sticky = $('#sideColumn').children('.sidebar');
$(window).scroll(function(){
t = $('#sideColumn').offset().top-20;
b = $('#contentArea').offset().top + $('#contentArea').height();
w = $('#sideColumn').width();
h = $(sticky).height();
if ($(window).scrollTop() < t) $(sticky).css({'width':'auto','position':'static'});
else if ($(window).scrollTop() >= t && $(window).scrollTop() < b-h) $(sticky).css({'width':w,'position':'fixed','top':'20px','bottom':'inherit'});
else if ($(window).scrollTop() >= b-h) {
$(sticky).css({'width':w,'position':'absolute','top':'inherit','bottom':'20px'});
if ($.browser.version == '7.0') $(sticky).css('top',$('#contentArea').height()-h);
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment