I was attempting to use this answer.
However, it's not working. It's always firing the else removing the sticky class from the div regardless if the footer is in view or not.
Here's the code:
$(window).scroll(function() {
var windowTop = $(this).scrollTop();
if (windowTop >= $("#site-footer").offset().top) {
console.log('sticky!')
$("div#desktop-cta").addClass("sticky-footer");
} else {
console.log('not sticky');
$("div#desktop-cta").removeClass("sticky-footer");
}
});
site-footer is the ID of the footer element of the page. desktop-cta is the element that requires the sticky-footer class to be added or removed. When looking at the console it only logs "not sticky".
How can it be fixed?