fusing the 2 js functions in 1 to animate 2 elements in certain conditions