CSS transition going backwards/reverse

匆匆过客 提交于 2019-12-11 05:53:15

问题


I'm wondering if is there any way to use the same CSS transition instance to both move it forward and then backwards/reverse. For example, lets say I have this transition:

@-webkit-keyframes fade-transition {
    from { opacity: 0; }
    to { opacity: 1; }
}

And two runners for this transition. One does the fade in and the other does the fade out:

.fade-in {
    -webkit-animation: fade-transition .2s linear backwards;
}

.fade-out {
    -webkit-animation: fade-transition .2s linear forwards;
}

What I want to accomplish is to use the same transition to do both the fade in and the fade out but the way I'm doing it doesn't work.

Here is the example on JSBin.


回答1:


Use percentage instead of from and to

@-webkit-keyframes fade-transition {
    0%, 100% { opacity: 0; }
    50% { opacity: 1; }
}

You can iterate this number of times you want or just set it to infinite



来源:https://stackoverflow.com/questions/14821343/css-transition-going-backwards-reverse

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