Skip to content

Instantly share code, notes, and snippets.

@friartuck6000
Last active December 19, 2015 15:39
Show Gist options
  • Save friartuck6000/5978211 to your computer and use it in GitHub Desktop.
Save friartuck6000/5978211 to your computer and use it in GitHub Desktop.
Make sidebars using Bootstrap's affix play nicely with responsive designs
$.fn.fluidAffix = function(opts){
return this.each(function(){
var $this = $(this);
var $parent = $this.parent();
// Match width of parent container
$this.css('width', $parent.width()+'px');
// Adjust top offset dynamically
var _top = $this.offset().top;
// If a container selector is supplied, add the offset difference for
// a cleaner transition
if (opts.container){
var _ctop = $(opts.container).offset().top;
_top += _top - _ctop;
}
$this.affix({
offset : {
top : _top
}
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment