TransitionJs icon indicating copy to clipboard operation
TransitionJs copied to clipboard

How to reset styles in onTransitionEnd?

Open leolux opened this issue 5 years ago • 2 comments

The method transition.begin(....) adds some styles to the DOM element. How to remove those styles at the end of the transition?

leolux avatar Oct 22 '19 12:10 leolux

@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 = "";
    }
  }
});

smnh avatar Oct 23 '19 15:10 smnh

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.

leolux avatar Nov 01 '19 12:11 leolux