Fix pagination position offset bug

When they are more than two pages, the pos variable keeps the same value.