Updated scroll function to detect userAgent