Callback when CSS3 transition finishes

后端 未结 5 1928
野的像风
野的像风 2020-11-22 09:30

I\'d like to fade out an element (transitioning its opacity to 0) and then when finished remove the element from the DOM.

In jQuery this is straight forward since yo

5条回答
  •  我在风中等你
    2020-11-22 10:16

    There is an animationend Event that can be observed see documentation here, also for css transition animations you could use the transitionend event

    There is no need for additional libraries these all work with vanilla JS

    document.getElementById("myDIV").addEventListener("transitionend", myEndFunction);
    function myEndFunction() {
    	this.innerHTML = "transition event ended";
    }
    #myDIV {transition: top 2s; position: relative; top: 0;}
    div {background: #ede;cursor: pointer;padding: 20px;}
    Click me to start animation.

提交回复
热议问题