TransitionJs
TransitionJs copied to clipboard
How to reset styles in onTransitionEnd?
The method transition.begin(....)
adds some styles to the DOM element. How to remove those styles at the end of the transition?
@leolux you can use the onTransitionEnd
callback function to clean the styles.
But it might undo the transition effect. For example, if you transition element's opacity from 1 to 0 and then clean its styles, then the element will jump to its default opacity of 1.
transition.begin(element, "opacity 1 0 1s", {
onTransitionEnd: function(element, finished) {
if (finished) {
// here we remove the style, and the element will instantly appear again.
element.style.cssText = "";
}
}
});
Yes, the element should jump to its default style after the transition has finished. But I can't simply remove all styles in onTransitionEnd
because my element already has some initial style which gets overwritten during the transition process.