function isScrolledIntoView(elem) { if (elem.length) { var docViewTop = $(window).scrollTop(); var docViewBottom = docViewTop + $(window).height(); var elemTop = $(elem).offset().top - 300; var elemBottom = elemTop + $(elem).height(); return ((elemBottom <= docViewBottom) && (elemTop >= docViewTop)); } } if (isScrolledIntoView($('.site-footer'))) { $('body').addClass('footer-visible'); } else { $('body').removeClass('footer-visible'); }