Javascript working correctly, scrolling and animation