Optimized function for detecting transitionend event name