How do I detect a transition end without a JavaScript library?

前端 未结 3 398
礼貌的吻别
礼貌的吻别 2021-01-11 12:04

I\'d like to delete an object after it\'s done animating with a CSS transition, but I\'m not able to use a JavaScript library.

How do I detect when the animation is

3条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-11 12:38

    element.addEventListener('transitionend', function(event) {
        alert("CSS Property completed: " + event.propertyName);
    }, false );
    

    For now, the exact event name has not been standardized. Here's a quote from MDN:

    There is a single event that is fired when transitions complete.
    In all standard-compliant browser, the event is transitionend,
    in WebKit it is webkitTransitionEnd.

    Here's the fiddle for Webkit: http://jsfiddle.net/bNgWY/

提交回复
热议问题