Cut a CSS transition short?

一世执手 提交于 2021-02-08 23:40:47

问题


I'm applying a CSS transition to an element.

   target.style.transition = "color 10000ms ease";
   target.style.color = "red";

Under certain circumstances, I want the end state of this transition to be reached immediately, without waiting for the transition to finish.

If I try

   target.style.transition = "color 0ms";
   target.style.color = "red";

the current transition just continues.

Doing

   target.style.transition = "color 0ms";
   target.style.color = "blue";

sets it to 'blue' immediately, while

   target.style.transition = "color 0ms";
   target.style.color = "blue";
   target.style.color = "red";

results in a continuation of the transition. (tried in both Chrome and FF)

Is there a way to stop the transition?


回答1:


To stop the transition and reach the end state immediately, use

target.style.transition = "none";

See DEMO.



来源:https://stackoverflow.com/questions/16376109/cut-a-css-transition-short

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!