Move anchor/viewport calculation outside the loop