Last active
December 19, 2015 15:39
-
-
Save friartuck6000/5978211 to your computer and use it in GitHub Desktop.
Make sidebars using Bootstrap's affix play nicely with responsive designs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.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