Skip to content

Instantly share code, notes, and snippets.

@johnbhartley
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnbhartley/73d1d19f2a05725a28d3 to your computer and use it in GitHub Desktop.
Save johnbhartley/73d1d19f2a05725a28d3 to your computer and use it in GitHub Desktop.
Holy terribly named variables Batman!
$(function() {
var $sidebar = $(".main-sidebar.sticky"),
preFooter = $('.pre-footer'),
bloggy = $('.main-content'),
blogHeight = bloggy.offset(),
$window = $(window),
offset = $sidebar.offset(),
preOffset = preFooter.offset(),
height = $sidebar.height(),
bigOffset = blogHeight.top + bloggy.height() - height,
topPadding = 15;
// on scroll this will calculate the height
$window.scroll(function() {
if ($window.scrollTop() > offset.top && $window.scrollTop() < bigOffset) {
console.log(height);
console.log(preOffset.top - height);
$sidebar.css('margin-top', $window.scrollTop() - offset.top + topPadding );
} else if($window.scrollTop() < offset.top) {
$sidebar.css('margin-top', '0' );
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment