Skip to content

Instantly share code, notes, and snippets.

@rayheberer
Last active June 9, 2017 18:36
Show Gist options
  • Save rayheberer/f4aa1ec81b5addc7a500fe2d1e775e6b to your computer and use it in GitHub Desktop.
Save rayheberer/f4aa1ec81b5addc7a500fe2d1e775e6b to your computer and use it in GitHub Desktop.
implements sticky sidebars on crestonlibrary.com, which uses a child theme of theme.co's X
jQuery(function($){
var leftposition = $('.x-sidebar').position().left;
$(window).scroll(function(){
if( $(this).scrollTop() >= ( $('.x-main').offset().top - $('.x-navbar-wrap').height() - 10 )
&& ( $(this).scrollTop() < ( $('.x-main').height() + $('.x-main').offset().top - $('.widget_nav_menu').height() - $('.x-navbar-wrap').height() ) ) ) {
$('.x-sidebar').css({position:'fixed', top:( $('.x-navbar-wrap').height() + 10 ),
left: leftposition });
}
else if ( $(this).scrollTop() >= ( $('.x-main').height() + $('.x-main').offset().top - $('.widget_nav_menu').height() - $('.x-navbar-wrap').height() ) ) {
$('.x-sidebar').css({position:'absolute', top: ( $('.x-main').offset().top + $('.x-main').height() - $('.widget_nav_menu').height() ),
left: leftposition });
}
else {
$('.x-sidebar').css({position:'absolute',
top: $('.x-main').offset().top,
left: leftposition });
}
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment