$(function(){ var needHelp = $(".sectionNeedHelp"); var content = $('.distributors section.sectionContent'); $(window).scroll(function() { var currentScrollTop = $(this).scrollTop(); var maxTop = content.outerHeight()-200; if (currentScrollTop > 555){ if (currentScrollTop > maxTop){ needHelp.css('position','fixed'); needHelp.css('top','10'); needHelp.css('bottom',null); }else{ needHelp.css('position','fixed'); needHelp.css('bottom','10'); needHelp.css('top',null); } }else{ needHelp.css('position','static'); } // console.log(currentScrollTop); }); });