Can't stop css animation disappearing after last key frame

ⅰ亾dé卋堺 提交于 2019-11-29 03:19:57

You need animation-fill-mode: forwards to prevent this from happening.

Additionally, you need to end with an opacity of 1, therefore the last frame must have an opacity of 1.

jsFiddle example - it works as expected now.

You can also shorten your keyframe by removing 0%, as this is already given in the initial state.

@keyframes santaappear {
    96% {
        opacity:1;
    }
    100% {
        opacity:1;
    }
}

You could also combine 96% and 100%.

@keyframes santaappear {
    96%, 100% {
        opacity:1;
    }
}

Since you are using multiple animation properties, use the animation shorthand:

<single-animation-name> || <time> || <timing-function> || <time> || <single-animation-iteration-count> || <single-animation-direction> || <single-animation-fill-mode>`

Which would be:

animation: santaappear 13s 2s forwards;
-moz-animation: santaappear 13s 2s forwards;
-webkit-animation: santaappear 13s 2s forwards;

In the demo, I added vendor prefixes for -moz/-webkit. In addition to these you should have one written without a prefix. Same goes for the keyframes.

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