Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.