event listener to wait for animations to finish before removing elements from the document