fixed infinite loops when element is not visible