function setupFixedButton() { var onScrollFunction = function(){ var scrollTop = $(window).scrollTop(); $('#fixedOrderButton').each(function() { var button = null; $(this).find('.fixedButton').each(function() { button = this; }); var bottomPadding = null; $(this).find('.bottomPadding').each(function() { bottomPadding = this; }); var y = 1; var point = document.getElementById('fixedOrderButtonDisplayPoint'); if (point) { y = $(point).offset().top; } var scrollTop = $(window).scrollTop(); if(scrollTop < y) { this.className = ''; } else { this.className = 'display'; if (bottomPadding && button) { bottomPadding.style.height = ($(button).innerHeight()+44)+'px'; } } }); } onScrollFunction(); $(document).on('scroll', onScrollFunction); } $(function() { setupFixedButton(); });