You need to set another waypoint in the footer, and when the sticky div is going to reach the footer (that is setup with the offset option), remove the .stuck
class that makes the div to be fixed (with a toggle, the .stuck
class comes again when the footer lets the sticky div to be displayed again). You achieve this with:
$('.footer').waypoint(function(direction) {
$('.sticky').toggleClass('stuck', direction === 'up')
}, {
offset: function() {
return $('.sticky').outerHeight()
}});
Check if that is what you want (hope so! :) ): https://jsfiddle.net/elbecita/mna64waw/3/
EDIT: I forgot one thing!! you need a class for the sticky div when the footer surpasses it, so the final js you need would be:
$('.footer').waypoint(function(direction) {
$('.sticky').toggleClass('stuck', direction === 'up');
$('.sticky').toggleClass('sticky-surpassed', direction === 'down');
}, { offset: function() {
return $('.sticky').outerHeight();
}});
and the .sticky-surpassed
would be:
.sticky-surpassed {
position:absolute;
bottom: 0;
}
Check update here: https://jsfiddle.net/elbecita/mna64waw/5/