Cleaned up the animation code for the onScroll handler.