Add check to onscroll functionality to ensure element is visible