Better way to handle animationEnd in JS