I'm working on a page that uses waypoints to create a sticky div that scrolls down the page with position: fixed until it reaches the bottom of its parent div. The code im using works as intended until $.waypoints('refresh') is called then the sticky div jumps back to the top of the page and loses its fixed position.
Heres the code:
$('#content').waypoint(function(event, direction){
if (direction === 'down') {
$(this).removeClass('sticky').addClass('bottomed');
}
else {
$(this).removeClass('bottomed').addClass('sticky');
}
}, {
offset: function() {
return $('#leftCol').outerHeight() - $('#content').outerHeight();
}
}).find('#leftCol').waypoint(function(event, direction) {
$(this).parent().toggleClass('sticky', direction === "down");
event.stopPropagation();
});
Where #leftCol is the div that scrolls down the page and #content is its parent div.
The css I have is:
#content {
width: 975px;
height: auto;
position: relative;
margin-top: 10px;
margin-bottom: 20px;
min-height: 800px;
}
#leftCol {
position: absolute;
width: 974px;
}
.sticky #leftCol {
position:fixed !important;
top:0 !important;
left: 50% !important;
width: 974px !important;
margin-left: -488px;
}
.bottomed #leftCol {
position: absolute !important;
bottom: 0px;
}
Any ideas on how to maintain the position of #leftCol when $.waypoints('refresh') is called would be much appreciated.
Thanks