Fix a bug when the grid is hidden

When the grid is hidden, for instance in a hidden div, the scroll and
the refresh function are inducing an infinite loop that is consuming
alle the ressources of the computer.
This fixes this bug...