$container = $('myElem'); $(":animated").promise().done( function() { if( $container[0].getBoundingClientRect().top < 50 ) { $('html,body').animate({scrollTop: $container.offset().top}, 800); }; });