A JavaScript function which controls in, active and out states of animated elements