0

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?

Community
  • 1
  • 1
Chris Lee
  • 13
  • 5
  • Your if condition is giving error. $("#site-footer").offset().top This is not working – Mr7-itsurdeveloper Sep 19 '14 at 04:48
  • If you do not have your own code (only one from mentioned answer), then you can also try [my code](http://stackoverflow.com/questions/25867126/stick-child-to-bottom-when-parent-div-touches-the-browser-bottom/25912519#25912519) from one of my previous answers. Maybe it is what you want. – Regent Sep 19 '14 at 04:53
  • Yes, I know the if condition is what's giving me grief, but I don't know why. Regent, I tried your code and it somewhat works, but it doesn't remove the sticky-footer class when #site-footer comes into view. It has to be all the way to the bottom of #site-footer then some weird flashing occurs... – Chris Lee Sep 19 '14 at 16:47

0 Answers0