Small change: only calculate size is element is visible on screen.