There is no reasonable “ curve ” to go from one display state to another, so in the current browser implementation, any transition that somehow involves display will not have any transition at all.
With this code:
pr_container.removeClass("hide"); pr_container.removeClass("transparent");
You can imagine that two statements are executed in one “blocking” queue, therefore the browser practically displays an element from class="hide transparent" to class="" , and, as indicated above, the hide class practically cancels any existing transition.
Using
pr_container.removeClass("hide"); setTimeout(function() { pr_container.removeClass("transparent"); }, 0);
You told the browser to remove the "transparent" class "as soon as possible, but not in the same queue", so the browser first removes the "hide", and then goes. Removing the "transparent" occurs when the browser considers that it has a supply of resources, so the transition does not become invalid.
source share