A new element is written to the DOM, then after 2 seconds it is deleted. How to animate this element at the time of removal from the DOM? For example, so that the block disappears evenly as if it dissolves. Interested in the most correct and simple example.
var warningEl = document.createElement('div'); warningEl.setAttribute('class', 'warning'); var message = document.createTextNode('Какое-то сообщение'); warningEl.appendChild(message); var container = document.getElementsByClassName('container')[0]; container.appendChild(warningEl); function animate() { container.removeChild(warningEl); } setTimeout(animate, 2000); } css
.warning { opacity: 1; transition-property: opacity;//какое свойство анимировать transition-duration: 2s;//длительность анимации transition-timing-function: ease;//на сколько быстро должно изменяться значение стилевого свойства для которого применяется эффект перехода }
transitionendevent ... speaks for itself. Subscribe to it and remove the block after the occurrence of this event - DmytrykaddEventListener- Dmytryk