I have been toying around with the JSFiddle found from the answer to this question. My problem is similar, except the div that I want to have scroll only a certain way down the page is supposed to be vertically centered on the left side of the window, not in the top-left corner. I tried making this modification to the JQuery:
$.fn.followTo = function ( pos ) {
var $this = this,
$window = $(windw);
$window.scroll(function(e){
if ($window.scrollTop() > pos) {
$this.css({
position: 'absolute',
top: pos
});
} else {
$this.css({
position: 'fixed',
top: 50%
});
}
});
But when I set top: 50% in the else, the scrolling doesn't stop at the specified pos and instead follows all the way down the page. Here's my full modified JSFiddle.
How do I properly modify this so that I can have the element fixed centered halfway vertically, but stop after a certain point?