I have a site with a bar on the left that should stay with the user. So when the user scrolls, the sidebar scrolls along until it's lets say 5px from the top of the page. From then on, it should be locked in place there.
Of course it's possible that the view-port is smaller than the left bar, so the left bar doesn't fully fit in the screen. Not really dramatic though. However I would like it if the user scrolls to the bottom, the bottom of the sidebar 'hits' the footer of the page and then scrolls along with the page again.
Here's the code I've got: a basic setup of my site and an attempt of the first part of my question (but you'll see it doesn't work): jsfiddle.
I think the first part of the question is rather clear, but the second part might be a bit hard to understand, so here's a mockup:
You can see that there is no text shown because the text is above the viewport.
Here's the js for my attempt for part one:
$(document).ready(function () {
var theLoc = 5;
var links = $('#left');
$(window).scroll(function () {
console.log('scroll');
if (theLoc >= $(window).scrollTop()) {
if (links.hasClass('fixed')) {
links.removeClass('fixed');
}
} else {
if (!links.hasClass('fixed')) {
links.addClass('fixed');
}
}
});
});
But possibly more a css issue:
.fixed {
position:fixed;
}
I tried specifying the height etc again (because it show up like very big), but with no advance.